diff --git a/CHANGES.md b/CHANGES.md
index e37e7b576f..a95c64b6f5 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -14,6 +14,7 @@ Core Changes:
Language Improvements:
+- (markdown) much improved code block support (#2382) [Josh Goebel][]
- (markdown) improve bold/italic nesting (#2382) [Josh Goebel][]
- (fortran) Add Fortran 2018 keywords and coarray intrinsics (#2361) [Sam Miller][]
- (delphi) highlight hexadecimal, octal, and binary numbers (#2370) [Robert Riebisch]()
diff --git a/src/languages/markdown.js b/src/languages/markdown.js
index ea02ee98e6..6d643bdee6 100644
--- a/src/languages/markdown.js
+++ b/src/languages/markdown.js
@@ -18,14 +18,20 @@ function(hljs) {
CODE = {
className: 'code',
variants: [
+ // TODO: fix to allow these to work with sublanguage also
+ { begin: '(`{3,})(.|\\n)*?\\1`*[ ]*', },
+ { begin: '(~{3,})(.|\\n)*?\\1~*[ ]*', },
+ // needed to allow markdown as a sublanguage to work
+ { begin: '```\\w*\\s*$', end: '```+[ ]*$' },
+ { begin: '~~~\\w*\\s*$', end: '~~~+[ ]*$' },
+ { begin: '`.+?`' },
{
- begin: '^```\\w*\\s*$', end: '^```[ ]*$'
- },
- {
- begin: '`.+?`'
- },
- {
- begin: '^( {4}|\\t)', end: '$',
+ begin: '(?=^( {4}|\\t))',
+ // use contains to gobble up multiple lines to allow the block to be whatever size
+ // but only have a single open/close tag vs one per line
+ contains: [
+ { begin: '^( {4}|\\t)', end: '(\\n)$' }
+ ],
relevance: 0
}
]
diff --git a/test/markup/markdown/code.expect.txt b/test/markup/markdown/code.expect.txt
index 881ec4420e..c50bd78a60 100644
--- a/test/markup/markdown/code.expect.txt
+++ b/test/markup/markdown/code.expect.txt
@@ -1,8 +1,38 @@
- var code = true;
-
+ var code = true;
+ var code = false;
+
```javascript
var code = true;
```
+````md
+```
+a = 'This is a code block in python'
+```
+````
+
+~~~
+tilde can be used also (github)
+~~~
+
+~~~~ ruby startline=3 $%@#$
+def foo(x)
+ return 3
+end
+~~~~~~~
+
+~~~~~~~something
+code here
+~~~~~~~
+
+```
+aaa
+~~~
+```
+
+ ```javascript
+ can be indented
+ ```
+
Inline `code`, and `more code`.
diff --git a/test/markup/markdown/code.txt b/test/markup/markdown/code.txt
index d9bed99184..e095534bc0 100644
--- a/test/markup/markdown/code.txt
+++ b/test/markup/markdown/code.txt
@@ -1,8 +1,38 @@
var code = true;
+ var code = false;
```javascript
var code = true;
```
+````md
+```
+a = 'This is a code block in python'
+```
+````
+
+~~~
+tilde can be used also (github)
+~~~
+
+~~~~ ruby startline=3 $%@#$
+def foo(x)
+ return 3
+end
+~~~~~~~
+
+~~~~~~~something
+code here
+~~~~~~~
+
+```
+aaa
+~~~
+```
+
+ ```javascript
+ can be indented
+ ```
+
Inline `code`, and `more code`.