Skip to content

Commit

Permalink
headers are also containable
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 1, 2020
1 parent 8c9eec4 commit 326af4e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/languages/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ function(hljs) {
HORIZONTAL_RULE = {
begin: '^[-\\*]{3,}', end: '$'
};
HEADER = {
className: 'section',
variants: [
{ begin: '^#{1,6}', end: '$' },
{ begin: '^.+?\\n[=-]{2,}$' }
]
};
CODE = {
className: 'code',
variants: [
Expand Down Expand Up @@ -108,19 +101,33 @@ function(hljs) {
BOLD.contains = BOLD.contains.concat(CONTAINABLE);
ITALIC.contains = ITALIC.contains.concat(CONTAINABLE);

CONTAINABLE = CONTAINABLE.concat(BOLD,ITALIC);

HEADER = {
className: 'section',
variants: [
{
begin: '^#{1,6}',
end: '$',
contains: CONTAINABLE
},
{
begin: '(?=^.+?\\n[=-]{2,}$)',
contains: [
{ begin: '^[=-]*$' },
{ begin: '^', end: "\\n", contains: CONTAINABLE },
]
}
]
};

BLOCKQUOTE = {
className: 'quote',
begin: '^>\\s+',
contains: [],
contains: CONTAINABLE,
end: '$',
};

BLOCKQUOTE.contains = BLOCKQUOTE.contains.concat(
CONTAINABLE,
BOLD,
ITALIC
)

return {
aliases: ['md', 'mkdown', 'mkd'],
contains: [
Expand Down
11 changes: 11 additions & 0 deletions test/markup/markdown/sections.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<span class="hljs-section"># hello world</span>

<span class="hljs-section">## hello world</span>

<span class="hljs-section">hello world
===========</span>

<span class="hljs-section"><span class="hljs-emphasis">*hello world*</span> or [<span class="hljs-string">google</span>](<span class="hljs-link">link</span>)
===========</span>

<span class="hljs-section"># <span class="hljs-emphasis">*hello world*</span> or [<span class="hljs-string">google</span>](<span class="hljs-link">link</span>)</span>
12 changes: 12 additions & 0 deletions test/markup/markdown/sections.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# hello world

## hello world

hello world
===========

*hello world* or [google](link)
===========

# *hello world* or [google](link)

0 comments on commit 326af4e

Please sign in to comment.