mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Refactor tag parsing of tags
The allowed tags are now a const at the top of the code. Adding a tag there, automatically assigns the property to the javascript object, if the tag is present in the data.
This commit is contained in:
parent
901df242b7
commit
f903090e0f
@ -7,6 +7,7 @@ let title = ''
|
||||
let sections = []
|
||||
let tasks = []
|
||||
let currentSection = ''
|
||||
const tags = ['active', 'done', 'crit', 'milestone']
|
||||
|
||||
export const clear = function () {
|
||||
sections = []
|
||||
@ -158,7 +159,7 @@ const compileData = function (prevTask, dataStr) {
|
||||
const task = {}
|
||||
|
||||
// Get tags like active, done, crit and milestone
|
||||
getTaskTags(data, task)
|
||||
getTaskTags(data, task, tags)
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
data[i] = data[i].trim()
|
||||
@ -199,7 +200,7 @@ const parseData = function (prevTaskId, dataStr) {
|
||||
const task = {}
|
||||
|
||||
// Get tags like active, done, crit and milestone
|
||||
getTaskTags(data, task)
|
||||
getTaskTags(data, task, tags)
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
data[i] = data[i].trim()
|
||||
@ -330,29 +331,18 @@ export default {
|
||||
addTaskOrg
|
||||
}
|
||||
|
||||
function getTaskTags (data, task) {
|
||||
function getTaskTags (data, task, tags) {
|
||||
let matchFound = true
|
||||
while (matchFound) {
|
||||
matchFound = false
|
||||
if (data[0].match(/^\s*active\s*$/)) {
|
||||
task.active = true
|
||||
data.shift(1)
|
||||
matchFound = true
|
||||
}
|
||||
if (data[0].match(/^\s*done\s*$/)) {
|
||||
task.done = true
|
||||
data.shift(1)
|
||||
matchFound = true
|
||||
}
|
||||
if (data[0].match(/^\s*crit\s*$/)) {
|
||||
task.crit = true
|
||||
data.shift(1)
|
||||
matchFound = true
|
||||
}
|
||||
if (data[0].match(/^\s*milestone\s*$/)) {
|
||||
task.milestone = true
|
||||
data.shift(1)
|
||||
matchFound = true
|
||||
}
|
||||
tags.forEach(function (t) {
|
||||
const pattern = '^\\s*' + t + '\\s*$'
|
||||
const regex = new RegExp(pattern)
|
||||
if (data[0].match(regex)) {
|
||||
task[t] = true
|
||||
data.shift(1)
|
||||
matchFound = true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user