mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 07:19:41 +02: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:
@@ -7,6 +7,7 @@ let title = ''
|
|||||||
let sections = []
|
let sections = []
|
||||||
let tasks = []
|
let tasks = []
|
||||||
let currentSection = ''
|
let currentSection = ''
|
||||||
|
const tags = ['active', 'done', 'crit', 'milestone']
|
||||||
|
|
||||||
export const clear = function () {
|
export const clear = function () {
|
||||||
sections = []
|
sections = []
|
||||||
@@ -158,7 +159,7 @@ const compileData = function (prevTask, dataStr) {
|
|||||||
const task = {}
|
const task = {}
|
||||||
|
|
||||||
// Get tags like active, done, crit and milestone
|
// Get tags like active, done, crit and milestone
|
||||||
getTaskTags(data, task)
|
getTaskTags(data, task, tags)
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
data[i] = data[i].trim()
|
data[i] = data[i].trim()
|
||||||
@@ -199,7 +200,7 @@ const parseData = function (prevTaskId, dataStr) {
|
|||||||
const task = {}
|
const task = {}
|
||||||
|
|
||||||
// Get tags like active, done, crit and milestone
|
// Get tags like active, done, crit and milestone
|
||||||
getTaskTags(data, task)
|
getTaskTags(data, task, tags)
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
data[i] = data[i].trim()
|
data[i] = data[i].trim()
|
||||||
@@ -330,29 +331,18 @@ export default {
|
|||||||
addTaskOrg
|
addTaskOrg
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTaskTags (data, task) {
|
function getTaskTags (data, task, tags) {
|
||||||
let matchFound = true
|
let matchFound = true
|
||||||
while (matchFound) {
|
while (matchFound) {
|
||||||
matchFound = false
|
matchFound = false
|
||||||
if (data[0].match(/^\s*active\s*$/)) {
|
tags.forEach(function (t) {
|
||||||
task.active = true
|
const pattern = '^\\s*' + t + '\\s*$'
|
||||||
data.shift(1)
|
const regex = new RegExp(pattern)
|
||||||
matchFound = true
|
if (data[0].match(regex)) {
|
||||||
}
|
task[t] = true
|
||||||
if (data[0].match(/^\s*done\s*$/)) {
|
data.shift(1)
|
||||||
task.done = true
|
matchFound = 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user