How to use the lowlight/lib/core.highlightAuto function in lowlight

To help you get started, we’ve selected a few lowlight 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 DefinitelyTyped / DefinitelyTyped / lowlight / lowlight-tests.ts View on Github external
console.log(core.highlight('javascript',
`class CPP {
    constructor(version) {
        this.version = version;
        this.year = Number(version.match(/.+\d+$/));
    }

    version(){
        return this.version;
    }
}
`
, { prefix: 'core-' }));


console.info(core.highlightAuto(
`class CPP {
    constructor(version) {
        this.version = version;
        this.year = Number(version.match(/.+\d+$/));
    }

    version(){
        return this.version;
    }
}
`
, { prefix: 'core-', subset: ['purescript', 'javascript', 'typescript', 'coffeescript'] }));
github rexxars / react-lowlight / src / Lowlight.js View on Github external
function Lowlight (props) {
  if (process.env.NODE_ENV !== 'production') {
    if (!props.language && registeredLanguages === 0) {
      console.warn(
        'No language definitions seems to be registered, ' +
          'did you forget to call `Lowlight.registerLanguage`?'
      )
    }
  }

  var result = props.language
    ? low.highlight(props.language, props.value, {prefix: props.prefix})
    : low.highlightAuto(props.value, {prefix: props.prefix, subset: props.subset})

  var codeProps = result.language ? {className: 'hljs ' + result.language} : {className: 'hljs'}

  if (props.inline) {
    codeProps.style = {display: 'inline'}
    codeProps.className = props.className
  }

  var ast = result.value
  if (props.markers && props.markers.length > 0) {
    ast = addMarkers(ast, {prefix: props.prefix, markers: props.markers})
  }

  var value = ast.length === 0 ? props.value : ast.map(mapChildren.depth(0))

  var code = h('code', codeProps, value)
github scrumpy / tiptap / packages / tiptap-extensions / src / nodes / CodeBlockHighlight.js View on Github external
blocks.forEach(block => {
    let startPos = block.pos + 1
    const nodes = low.highlightAuto(block.node.textContent).value

    flatten(parseNodes(nodes))
      .map(node => {
        const from = startPos
        const to = from + node.text.length

        startPos = to

        return {
          ...node,
          from,
          to,
        }
      })
      .forEach(node => {
        const decoration = Decoration.inline(node.from, node.to, {