Skip to content

Regex - handle indentation for blocks #3417

Answered by ivanjaros
ivanjaros asked this question in Q&A
Discussion options

You must be logged in to vote

Seems i have finally figured it out. I was on the right track:

const nestTest = {
  name: 'nest-test',
  level: 'block',
  start(src) {
    return src.match(/:::(info|warn|positive|negative)\n/)?.index;
    },
  tokenizer(src, tokens) {
    const match = src.match(/^:::(info|warn|positive|negative)\n/)
    if (!match) {
      return
    }

    const lines = src.split("\n")
    const replaced = []
    replaced.push(lines.shift()) // ignore opening tag but preserve it for "raw"

    const groups = []
    let group = []
    let indent = 0

    for (let line of lines) {
      if (indent === 0 && line.length === 0) {
        break
      }
      const offset = countIndent(line)
      if (indent > 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ivanjaros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant