How to use @textlint/markdown-to-ast - 10 common examples

To help you get started, we’ve selected a few @textlint/markdown-to-ast 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 fannypackui / fannypack / packages / website / scripts / inject-types.js View on Github external
const typeMarkdown = getTypeMarkdown(localType, typeReferences, { type });

        let title;
        if (type === 'state-return') {
          title = 'Return Values';
        }
        if (type === 'state-api') {
          title = 'API';
        }
        if (type === 'props') {
          title = 'Props';
        }

        try {
          const tree = ast.parse(mdContents);
          const merged = inject(`${componentSection} ${title}`, tree, ast.parse(typeMarkdown));
          const markdown = toMarkdown(merged).trimLeft();
          writeFileSync(docPath, markdown);
          console.log(`Injected ${componentSection} props into ${docPath}`);
        } catch (e) {
          // do nothing
        }
      });
    }
github fannypackui / fannypack / packages / website / scripts / inject-types.js View on Github external
}
        const typeMarkdown = getTypeMarkdown(localType, typeReferences, { type });

        let title;
        if (type === 'state-return') {
          title = 'Return Values';
        }
        if (type === 'state-api') {
          title = 'API';
        }
        if (type === 'props') {
          title = 'Props';
        }

        try {
          const tree = ast.parse(mdContents);
          const merged = inject(`${componentSection} ${title}`, tree, ast.parse(typeMarkdown));
          const markdown = toMarkdown(merged).trimLeft();
          writeFileSync(docPath, markdown);
          console.log(`Injected ${componentSection} props into ${docPath}`);
        } catch (e) {
          // do nothing
        }
      });
    }
github thlorenz / doctoc / lib / transform.js View on Github external
return extractText(x);
        }
        else if (x.type === md.Syntax.Image) {
          // Images (at least on GitHub, untested elsewhere) are given a hyphen
          // in the slug. We can achieve this behavior by adding an '*' to the
          // TOC entry. Think of it as a "magic char" that represents the iamge.
          return '*';
        }
        else {
          return x.raw;
        }
      })
      .join('')
  }

  return md.parse(lines.join('\n')).children
    .filter(function (x) {
      return x.type === md.Syntax.Header;
    })
    .map(function (x) {
      return !maxHeaderLevel || x.depth <= maxHeaderLevel
        ? { rank :  x.depth
          , name :  extractText(x)
          , line :  x.loc.start.line
          }
        : null;
    })
    .filter(notNull)
}
github thlorenz / doctoc / lib / get-html-headers.js View on Github external
var go = module.exports = function (lines, maxHeaderLevel) {
  var source = md.parse(lines.join('\n'))
    .children
    .filter(function(node) {
      return node.type === md.Syntax.HtmlBlock || node.type === md.Syntax.Html;
    })
    .map(function (node) {
      return node.raw;
    })
    .join('\n');

  //var headers = [], grabbing = null, text = [];
  var headers = [], grabbing = [], text = [];

  var parser = new htmlparser.Parser({
    onopentag: function (name, attr) {
      // Short circuit if we're already inside a pre
      if (grabbing[grabbing.length - 1] === 'pre') return;
github thlorenz / doctoc / lib / transform.js View on Github external
.map(function (x) {
        if (x.type === md.Syntax.Link) {
          return extractText(x);
        }
        else if (x.type === md.Syntax.Image) {
          // Images (at least on GitHub, untested elsewhere) are given a hyphen
          // in the slug. We can achieve this behavior by adding an '*' to the
          // TOC entry. Think of it as a "magic char" that represents the iamge.
          return '*';
        }
        else {
          return x.raw;
        }
      })
      .join('')
github reakit / reakit / scripts / build / utils.js View on Github external
readmePaths.forEach(readmePath => {
    const mdContents = readFileSync(readmePath, { encoding: "utf-8" });

    if (/#\s?Props/.test(mdContents)) {
      const dir = dirname(readmePath);
      const tree = ast.parse(mdContents);
      const publicPaths = Object.values(getPublicFiles(dir));
      const sourceFiles = project.addExistingSourceFiles(publicPaths);
      project.resolveSourceFileDependencies();
      const types = {};

      sortSourceFiles(sourceFiles).forEach(sourceFile => {
        sourceFile.forEachChild(node => {
          if (isStateReturnDeclaration(node)) {
            const propTypes = createPropTypeObjects(rootPath, node);
            stateTypes.push(...propTypes.map(prop => prop.name));
          }
          if (isPropsDeclaration(node)) {
            const moduleName = getModuleName(node);
            const propTypes = createPropTypeObjects(rootPath, node);

            if (isInitialStateDeclaration(node)) {
github Waiviogit / waivio / src / client / components / EditorExtended / util / markdownToEditorState.js View on Github external
const parseMdLine = (line, existingEntities, extraStyles = {}) => {
  const inlineStyles = { ...defaultInlineStyles, ...extraStyles.inlineStyles };
  const blockStyles = { ...defaultBlockStyles, ...extraStyles.blockStyles };

  const astString = mdToAst.parse(line);
  let text = '';
  const inlineStyleRanges = [];
  const entityRanges = [];
  const data = {};
  const entityMap = existingEntities;

  const addInlineStyleRange = (offset, length, style) => {
    inlineStyleRanges.push({ offset, length, style });
  };

  const getRawLength = children =>
    children.reduce((prev, current) => prev + (current.value ? current.value.length : 0), 0);

  const addObject = child => {
    const entityKey = Object.keys(entityMap).length;
    const urlParts = child.url.split('/');
github kadikraman / draftjs-md-converter / src / mdToDraftjs.js View on Github external
const parseMdLine = (line, existingEntities, extraStyles = {}) => {
  const inlineStyles = { ...defaultInlineStyles, ...extraStyles.inlineStyles };
  const blockStyles = { ...defaultBlockStyles, ...extraStyles.blockStyles };

  const astString = parse(line);
  let text = '';
  const inlineStyleRanges = [];
  const entityRanges = [];
  const entityMap = existingEntities;

  const addInlineStyleRange = (offset, length, style) => {
    inlineStyleRanges.push({ offset, length, style });
  };

  const getRawLength = children =>
    children.reduce((prev, current) => {
      if (current.value) {
        return prev + current.value.length;
      } else if (current.children && current.children.length) {
        return prev + getRawLength(current.children);
      }
github textlint / textlint / packages / @textlint / textlint-plugin-markdown / src / MarkdownProcessor.js View on Github external
preProcess(text, filePath) {
                return parse(text);
            },
            postProcess(messages, filePath) {
github thlorenz / doctoc / lib / transform.js View on Github external
.filter(function (x) {
      return x.type === md.Syntax.Header;
    })
    .map(function (x) {

@textlint/markdown-to-ast

Parse Markdown to AST with location info.

MIT
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis

Popular @textlint/markdown-to-ast functions

Similar packages