Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 45 additions & 30 deletions src/languages/asciidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export default function(hljs) {
// guard: constrained formatting mark may not be preceded by ":", ";" or
// "}". match these so the constrained rule doesn't see them
{
begin: /[:;}][*_`](?!\*)/
begin: /[:;}][*_`](?![*_`])/
}
];

const STRONG = [
// inline unconstrained strong (single line)
{
Expand Down Expand Up @@ -69,6 +68,49 @@ export default function(hljs) {
begin: /\*[^\s]([^\n]+\n)+([^\n]+)\*/
}
];
const EMPHASIS = [
// inline unconstrained emphasis (single line)
{
className: 'emphasis',
begin: /_{2}([^\n]+?)_{2}/
},
// inline unconstrained emphasis (multi-line)
{
className: 'emphasis',
begin: regex.concat(
/__/,
/((_(?!_)|\\[^\n]|[^_\n\\])+\n)+/,
/(_(?!_)|\\[^\n]|[^_\n\\])*/,
/__/
),
relevance: 0
},
// inline constrained emphasis (single line)
{
className: 'emphasis',
// must not precede or follow a word character
begin: /\b_(\S|\S[^\n]*?\S)_(?!\w)/
},
// inline constrained emphasis (multi-line)
{
className: 'emphasis',
// must not precede or follow a word character
begin: /_[^\s]([^\n]+\n)+([^\n]+)_/
},
// inline constrained emphasis using single quote (legacy)
{
className: 'emphasis',
// must not follow a word character or be followed by a single quote or space
begin: '\\B\'(?![\'\\s])',
end: '(\\n{2}|\')',
// allow escaped single quote followed by word char
contains: [{
begin: '\\\\\'\\w',
relevance: 0
}],
relevance: 0
}
];
const ADMONITION = {
className: 'symbol',
begin: '^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+',
Expand Down Expand Up @@ -171,35 +213,8 @@ export default function(hljs) {
ADMONITION,
...ESCAPED_FORMATTING,
...STRONG,
...EMPHASIS,

// TODO emphasis and code should get same treatment as strong!
// inline unconstrained emphasis
{
className: 'emphasis',
begin: /_{2}/,
end: /(\n{2}|_{2})/
},
// inline emphasis
{
className: 'emphasis',
// must not follow a word character or be followed by a single quote or space
begin: '\\B\'(?![\'\\s])',
end: '(\\n{2}|\')',
// allow escaped single quote followed by word char
contains: [{
begin: '\\\\\'\\w',
relevance: 0
}],
relevance: 0
},
// inline emphasis (alt)
{
className: 'emphasis',
// must not follow a word character or be followed by an underline or space
begin: '_(?![_\\s])',
end: '(\\n{2}|_)',
relevance: 0
},
// inline smart quotes
{
className: 'string',
Expand Down
46 changes: 46 additions & 0 deletions test/markup/asciidoc/constrained.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,49 @@ best*</span>
<span class="hljs-strong">*does bob
-really-
know best?*</span>

Some emphasis on [#emphasis]<span class="hljs-emphasis">_that_</span>.

The word \_underscore_ is not rendered as italic.

Use the _ symbol. Read the footnotes_. You can also type_ this symbol _.

An important <span class="hljs-emphasis">_wo
rd_</span>.

Not an important _wo

rd_.

\\blah blah <span class="hljs-emphasis">_blah_</span>.

\\blah blah blah_.

Does <span class="hljs-emphasis">_Bob -love- Gemma_</span>?

Does <span class="hljs-emphasis">_Bob &quot;love&quot; Gemma_</span>?

Does <span class="hljs-emphasis">_Bob love Gemma? Truly?_</span>

There&#x27;s a colon:_directly_ before the starting formatting mark.

There&#x27;s a semi-colon directly before the starting formatting mark &amp;ndash;_2018_

There&#x27;s a closing curly bracket directly {before}_the starting formatting mark_.

<span class="hljs-emphasis">_bl_ck_</span>-eye

E = mc_2_

E = _mc_2

The parser is working <span class="hljs-emphasis">_99%_</span> of the time

<span class="hljs-emphasis">_bob
knows
very
best_</span>

<span class="hljs-emphasis">_does bob
-really-
know best?_</span>
46 changes: 46 additions & 0 deletions test/markup/asciidoc/constrained.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,49 @@ best*
*does bob
-really-
know best?*

Some emphasis on [#emphasis]_that_.

The word \_underscore_ is not rendered as italic.

Use the _ symbol. Read the footnotes_. You can also type_ this symbol _.

An important _wo
rd_.

Not an important _wo

rd_.

\\blah blah _blah_.

\\blah blah blah_.

Does _Bob -love- Gemma_?

Does _Bob "love" Gemma_?

Does _Bob love Gemma? Truly?_

There's a colon:_directly_ before the starting formatting mark.

There's a semi-colon directly before the starting formatting mark &ndash;_2018_

There's a closing curly bracket directly {before}_the starting formatting mark_.

_bl_ck_-eye

E = mc_2_

E = _mc_2

The parser is working _99%_ of the time

_bob
knows
very
best_

_does bob
-really-
know best?_
2 changes: 1 addition & 1 deletion test/markup/asciidoc/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ I&#x27;ll join that party, too.
<span class="hljs-section">===== Level 4 Section Title =====</span>
<span class="hljs-section">====== Level 5 Section Title ======</span>

<span class="hljs-symbol">NOTE: </span>AsciiDoc is quite cool, you should try it.
<span class="hljs-symbol">NOTE: </span>AsciiDoc is quite cool, you should try it.
2 changes: 1 addition & 1 deletion test/markup/asciidoc/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ I'll join that party, too.
===== Level 4 Section Title =====
====== Level 5 Section Title ======

NOTE: AsciiDoc is quite cool, you should try it.
NOTE: AsciiDoc is quite cool, you should try it.
39 changes: 39 additions & 0 deletions test/markup/asciidoc/unconstrained.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,42 @@ Git[.blue]<span class="hljs-strong">**Hub**</span>
knows
very
best**</span>

A sentence <span class="hljs-emphasis">__ with words, and more words!
using italic style :)__</span>.

Read the little notes__.

Read the little notes__

This is <span class="hljs-emphasis">__italic__</span>

E = <span class="hljs-emphasis">__mc__</span>2

<span class="hljs-emphasis">__Bob went with _Sarah_ to the market today.__</span>

<span class="hljs-emphasis">__Bob went with _Sarah_
to the market today.__</span>

There&#x27;s a colon:<span class="hljs-emphasis">__directly__</span> before the starting formatting mark.

There&#x27;s a semi-colon directly before the starting formatting mark &amp;ndash;<span class="hljs-emphasis">__2018__</span>

There&#x27;s a closing curly bracket directly {before}<span class="hljs-emphasis">__the starting formatting mark__</span>.

<span class="hljs-emphasis">__--anything goes __</span>

\\__--anything goes __

\\__--anything goes __ with _ a __lot__ of underscores__

<span class="hljs-emphasis">__Git__</span>Hub

<span class="hljs-emphasis">__bl_ck__</span>-eye

Git[.blue]<span class="hljs-emphasis">__Hub__</span>

<span class="hljs-emphasis">__bob
knows
very
best__</span>
39 changes: 39 additions & 0 deletions test/markup/asciidoc/unconstrained.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,42 @@ Git[.blue]**Hub**
knows
very
best**

A sentence __ with words, and more words!
using italic style :)__.

Read the little notes__.

Read the little notes__

This is __italic__

E = __mc__2

__Bob went with _Sarah_ to the market today.__

__Bob went with _Sarah_
to the market today.__

There's a colon:__directly__ before the starting formatting mark.

There's a semi-colon directly before the starting formatting mark &ndash;__2018__

There's a closing curly bracket directly {before}__the starting formatting mark__.

__--anything goes __

\\__--anything goes __

\\__--anything goes __ with _ a __lot__ of underscores__

__Git__Hub

__bl_ck__-eye

Git[.blue]__Hub__

__bob
knows
very
best__