Wiredcraft / jekyllpro-cms

A lightweight CMS for Jekyll websites.
http://jekyllpro.com/#cms
MIT License
7 stars 2 forks source link

Convert result text #3

Closed EcutDavid closed 7 years ago

EcutDavid commented 8 years ago

Currently, the result file is converted based on form data, and the original file.

Code in Editor

updateResult(formData) {
    const { content, fileIndex, filesMeta, schema, updateFile } = this.props
    let markdownText = content
    const docConfigObj = parseYamlInsideMarkdown(markdownText)
    if(!docConfigObj) return

    const schemaObj = schema.properties
    for (let i = 0; i < schemaObj.length; i++) {
      const linePattern = new RegExp(schemaObj[i].target + ': ?[\\w 、\/]*')

      const prePattern = new RegExp(schemaObj[i].target + ': ?')
      let newValue = formData[schemaObj[i].name]
      const preText = prePattern.exec(markdownText)[0]
      markdownText = markdownText.replace(linePattern, preText + newValue)
    }
    const targetContent = retriveContent(markdownText)
    this.setState({ resultMarkdown: markdownText, targetContent })

    updateFile(filesMeta[fileIndex].path, markdownText + targetContent)
  }

We have to replace the regexp stuff to something like JSON.stringfy.

Because current regexp just support yaml like


---
  a: b
  c: d
  e: f

---

But yaml with array values won't supported.


---
  a: b
  c:
    - j
    - k
  e: f

---

I'm using js-yaml for parse yaml const doc = yaml.safeLoad(text)(https://github.com/Wiredcraft/jekyllplus/blob/6eb6f13cd7f8d5ff1e0fe735919fc5524f8404cc/client/src/helpers/markdown.js#L35)

Maybe they also support dump the js object to yaml(https://github.com/nodeca/js-yaml).

woodpig07 commented 7 years ago

Not relevant any more, closing