Skip to content

Instantly share code, notes, and snippets.

@mendes5
Created June 26, 2022 04:50
Show Gist options
  • Select an option

  • Save mendes5/dcfe73edafd3d6f6802d6e4e73fd8dfe to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/dcfe73edafd3d6f6802d6e4e73fd8dfe to your computer and use it in GitHub Desktop.
Pretty print a micromark events list
console.log(self.events.map(x => [x[0], x[1].type, x[2].sliceSerialize(x[1], true)]).map(x => x.join(' | ')).reduce((prev, curr) => {
if (curr.startsWith('enter')) {
prev = { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr };
prev.i+=2
return prev
} else {
prev.i-=2
return { i: prev.i, t: prev.t + '\n' + ' '.repeat(prev.i) + curr }
}
}, { i: 0, t: '' }).t)
createProcessor().process(`

# Test { 1 +  1}

\`\`\`js
console.log(1 + 1 [ {} ]);
\`\`\`


And This {3 + 2} s [is](https://www.io.com) good [Go {s} x {s} to {my} website](https://rx-js.io)

`)

logs (when debbuging somewhere in the middle)

enter | data | And This 
exit | data | And This 
enter | mdxTextExpression | {3 + 2}
  enter | mdxTextExpressionMarker | {
  exit | mdxTextExpressionMarker | {
  enter | mdxTextExpressionChunk | 3 + 2
  exit | mdxTextExpressionChunk | 3 + 2
  enter | mdxTextExpressionMarker | }
  exit | mdxTextExpressionMarker | }
exit | mdxTextExpression | {3 + 2}
enter | data |  s 
exit | data |  s 
enter | link | [is](https://www.io.com)
  enter | label | [is]
    enter | labelMarker | [
    exit | labelMarker | [
    enter | labelText | is
      enter | data | is
      exit | data | is
    exit | labelText | is
    enter | labelMarker | ]
    exit | labelMarker | ]
  exit | label | [is]
  enter | resource | (https://www.io.com)
    enter | resourceMarker | (
    exit | resourceMarker | (
    enter | resourceDestination | https://www.io.com
      enter | resourceDestinationRaw | https://www.io.com
        enter | resourceDestinationString | https://www.io.com
          enter | chunkString | https://www.io.com
          exit | chunkString | https://www.io.com
        exit | resourceDestinationString | https://www.io.com
      exit | resourceDestinationRaw | https://www.io.com
    exit | resourceDestination | https://www.io.com
    enter | resourceMarker | )
    exit | resourceMarker | )
  exit | resource | (https://www.io.com)
exit | link | [is](https://www.io.com)
enter | data |  good 
exit | data |  good 
enter | labelLink | [
  enter | labelMarker | [
  exit | labelMarker | [
exit | labelLink | [
enter | data | Go 
exit | data | Go 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment