How to use hastscript - 10 common examples

To help you get started, we’ve selected a few hastscript 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 SAP / luigi / website / docs / src / unified-plugins / rehype-copy-to-clipboard.js View on Github external
function modify(node, prop) {
    const notYetProcessed = !node.properties.className || node.properties.className.indexOf('canCopyCode') === -1; // prevent infinite loop
    if (node.tagName === 'pre' && notYetProcessed) {
      // Docu: https://github.com/syntax-tree/hastscript#use
      const newNodeData = h('div.copyCodeContainer', [
        h('a.copyCode', { onclick: 'copyCode(event, this)' }, 
          [h('div', [
            h('img', { src: prependForExport() + '/images/copy-clipboard-default.svg' }),
            h('.popoverCopy', [
              'Click to copy'
            ])]
          )]
        ),
        h('pre.canCopyCode', node.children)
      ]);
      Object.assign(node, newNodeData);
    }
  }
}
github SAP / luigi / website / docs / src / unified-plugins / rehype-copy-to-clipboard.js View on Github external
function modify(node, prop) {
    const notYetProcessed = !node.properties.className || node.properties.className.indexOf('canCopyCode') === -1; // prevent infinite loop
    if (node.tagName === 'pre' && notYetProcessed) {
      // Docu: https://github.com/syntax-tree/hastscript#use
      const newNodeData = h('div.copyCodeContainer', [
        h('a.copyCode', { onclick: 'copyCode(event, this)' }, 
          [h('div', [
            h('img', { src: prependForExport() + '/images/copy-clipboard-default.svg' }),
            h('.popoverCopy', [
              'Click to copy'
            ])]
          )]
        ),
        h('pre.canCopyCode', node.children)
      ]);
      Object.assign(node, newNodeData);
    }
  }
}
github SAP / luigi / website / docs / src / unified-plugins / rehype-copy-to-clipboard.js View on Github external
function modify(node, prop) {
    const notYetProcessed = !node.properties.className || node.properties.className.indexOf('canCopyCode') === -1; // prevent infinite loop
    if (node.tagName === 'pre' && notYetProcessed) {
      // Docu: https://github.com/syntax-tree/hastscript#use
      const newNodeData = h('div.copyCodeContainer', [
        h('a.copyCode', { onclick: 'copyCode(event, this)' }, 
          [h('div', [
            h('img', { src: prependForExport() + '/images/copy-clipboard-default.svg' }),
            h('.popoverCopy', [
              'Click to copy'
            ])]
          )]
        ),
        h('pre.canCopyCode', node.children)
      ]);
      Object.assign(node, newNodeData);
    }
  }
}
github SAP / luigi / website / docs / src / unified-plugins / rehype-copy-to-clipboard.js View on Github external
function modify(node, prop) {
    const notYetProcessed = !node.properties.className || node.properties.className.indexOf('canCopyCode') === -1; // prevent infinite loop
    if (node.tagName === 'pre' && notYetProcessed) {
      // Docu: https://github.com/syntax-tree/hastscript#use
      const newNodeData = h('div.copyCodeContainer', [
        h('a.copyCode', { onclick: 'copyCode(event, this)' }, 
          [h('div', [
            h('img', { src: prependForExport() + '/images/copy-clipboard-default.svg' }),
            h('.popoverCopy', [
              'Click to copy'
            ])]
          )]
        ),
        h('pre.canCopyCode', node.children)
      ]);
      Object.assign(node, newNodeData);
    }
  }
}
github Mr0grog / google-docs-to-markdown / lib / fix-google-html.js View on Github external
visit(node, isStyled, (node, index, parent) => {
    const style = node.properties.style;
    if (/font-style:\s*italic/.test(style)) {
      wrapChildren(node, hast('em'));
    }
    if (/font-weight:\s*(bold|700)/.test(style)) {
      wrapChildren(node, hast('strong'));
    }
  });
}
github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
function mapImageTreeToSvg(node: ImageNode): SvgElement {
  switch (node.type) {
    case IMAGE: {
      let box = BBox.empty()
      unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
        box = BBox.add(box, layer.size)
      })
      const [xMin, yMin, width, height] = BBox.toViewBox(box)
      const props = {
        ...BASE_SVG_PROPS,
        width,
        height,
        viewBox: `${xMin} ${yMin} ${width} ${height}`,
      }
      return s('svg', props)
    }

    case IMAGE_LAYER: {
      const vbox = BBox.toViewBox(node.size)
      return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
      })
    }

    case IMAGE_SHAPE: {
      return renderShape(node)
    }

    case IMAGE_PATH:
    case IMAGE_REGION: {
      return renderPath(node)
github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
        box = BBox.add(box, layer.size)
      })
      const [xMin, yMin, width, height] = BBox.toViewBox(box)
      const props = {
        ...BASE_SVG_PROPS,
        width,
        height,
        viewBox: `${xMin} ${yMin} ${width} ${height}`,
      }
      return s('svg', props)
    }

    case IMAGE_LAYER: {
      const vbox = BBox.toViewBox(node.size)
      return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
      })
    }

    case IMAGE_SHAPE: {
      return renderShape(node)
    }

    case IMAGE_PATH:
    case IMAGE_REGION: {
      return renderPath(node)
    }
  }

  return s('metadata', [JSON.stringify(node)])
}
github ben-eb / midas / src / toVDOM.js View on Github external
getContent (node: Object) {
        this.ast = [];
        this.handle(node);
        const code = h('code', this.ast);

        if (this.wrap) {
            return h('pre.midas', code);
        }

        return code;
    }
github ben-eb / midas / src / toVDOM.js View on Github external
getContent (node: Object) {
        this.ast = [];
        this.handle(node);
        const code = h('code', this.ast);

        if (this.wrap) {
            return h('pre.midas', code);
        }

        return code;
    }
github BoostIO / BoostNote.next / src / components / atoms / MarkdownPreviewer.tsx View on Github external
CodeMirror.runMode(rawContent, mime, (text, style) => {
            cmResult.push(
              h(
                'span',
                {
                  className: style
                    ? 'cm-' + style.replace(/ +/g, ' cm-')
                    : undefined
                },
                text
              )
            )
          })
        } else if (!ignoreMissing) {

hastscript

hast utility to create trees

MIT
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis

Popular hastscript functions