How to use the @uiengine/util/src/markdown.parseString function in @uiengine/util

To help you get started, we’ve selected a few @uiengine/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dennisreimann / uiengine / packages / cli / src / yaml.js View on Github external
const R = require('ramda')
const { readFileSync } = require('fs')
const { dirname, isAbsolute, join, resolve } = require('path')
const assert = require('assert')
const yaml = require('js-yaml')
const parsing = require('@uiengine/util/src/parsing')
const Markdown = require('@uiengine/util/src/markdown')
const { invalidateRequireCache } = require('@uiengine/util/src/file')
const { markSample } = require('@uiengine/util/src/message')
const { UiengineInputError } = require('@uiengine/util/src/error')

const renderMarkdown = Markdown.parseString

const fromExternalFile = (embeddingFilePath, sourcePaths, filePath) => {
  const isYAML = filePath.match(/\.ya?ml$/)
  const isJS = filePath.match(/\.js(on)?$/)
  const isMarkdown = filePath.match(/\.(md|markdown)?$/)

  if (isYAML) {
    const string = readFileSync(filePath, 'utf8')
    return parseString(string, filePath, sourcePaths)
  } else if (isMarkdown) {
    const string = readFileSync(filePath, 'utf8')
    return renderMarkdown(string, filePath, sourcePaths)
  } else if (isJS) {
    // invalidate require cache so that changes are reflected
    invalidateRequireCache(filePath)
    return require(filePath)