Skip to content

Instantly share code, notes, and snippets.

@ggrossetie
Created July 24, 2018 21:33
Show Gist options
  • Save ggrossetie/4d999c3229f0f2d8e88c0b2b08329770 to your computer and use it in GitHub Desktop.
Save ggrossetie/4d999c3229f0f2d8e88c0b2b08329770 to your computer and use it in GitHub Desktop.

Inline quote parser

Unterminated markup (constrained)

*hello
[
  Inline(:plain, text='*hello')
]

Constrained quotes are single characters (often symbols) placed around a word.

The asterisk symbol should be around a word or a sequence of words. In this case the markup is unterminated. As a consequence the text is considered as "plain".

Unterminated markup (unconstrained)

**hello
[
  Inline(:plain, text='**hello')
]

Unconstrained quotes are repeated characters (often symbols) placed anywhere in the text, including within a word.

The double asterisk symbols should be within a word. In this case the markup is unterminated. As a consequence the text is considered as "plain".

Note

We could also consider that the markup is constrained on an empty text:

[
  Inline(:bold,  text=''),
  Inline(:plain, text='hello')
]

Simplified as:

[
  Inline(:plain, text='hello')
]

But since the text is empty, we could consider the symbols as "plain" text:

[
  Inline(:plain, text='**hello')
]

Three quote symbols

***hello
Proposal #1: constrained quote around the word "*"
[
  Inline(:bold,  text='*'),
  Inline(:plain, text='hello')
]
Proposal #2: unterminated unconstrained quote around the word "*hello"
[
  Inline(:plain, text='***hello')
]

Four quote symbols

****hello
Proposal #1: constrained quote around the word "*"
[
  Inline(:bold,  text='*'),
  Inline(:plain, text='*hello')
]

The first three symbols are translated as a constrained quote around the "word" asterisk. The last symbol is an orphan and will be considered as "plain" text.

Note

In other words, the parser should stop as soon as a constrained quote ends.

Proposal #2: unconstrained quote around an empty text
[
  Inline(:bold,  text=''),
  Inline(:plain, text='hello')
]

Simplified as:

[
  Inline(:plain, text='hello')
]

But since the text is empty, we could consider the symbols as "plain" text:

[
  Inline(:plain, text='****hello')
]

Unconstrained greedy (start)

***h**ello
Proposal #1: Start as soon as possible
[
  Inline(:bold,  text='*h'),
  Inline(:plain, text='ello')
]
Proposal #2: Start as late as possible
[
  Inline(:plain, text='*'),
  Inline(:bold,  text='h'),
  Inline(:plain, text='ello')
]

Unconstrained greedy (end)

***h***ello
Proposal #1: Start as soon as possible and end as late as possible
[
  Inline(:bold,  text='*h*'),
  Inline(:plain, text='ello')
]
Proposal #2: Start as late as possible and end as soon as possible
[
  Inline(:plain, text='*'),
  Inline(:bold,  text='h'),
  Inline(:plain, text='*ello')
]
Proposal #3: Start as soon as possible and end as soon as possible
[
  Inline(:bold,  text='*h'),
  Inline(:plain, text='*ello')
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment