Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-19964 Properly handle whitespace before code block language (#4186)
Browse files Browse the repository at this point in the history
* MM-19964 Properly handle whitespace before code block language

* Update marked to merge commit
  • Loading branch information
hmhealey committed Nov 13, 2019
1 parent 5516f5d commit 6745a6e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@types/highlight.js": "9.12.3",
"@formatjs/intl-pluralrules": "1.3.1",
"@formatjs/intl-relativetimeformat": "4.4.0",
"@types/highlight.js": "9.12.3",
"@typescript-eslint/parser": "2.6.0",
"bootstrap": "3.4.1",
"bootstrap-colorpicker": "2.5.2",
Expand All @@ -34,7 +34,7 @@
"localforage": "1.7.3",
"localforage-observable": "2.0.0",
"mark.js": "8.11.1",
"marked": "github:mattermost/marked#3a8d6ffc804de8ecd6b749ef8ebc9a4a94067b80",
"marked": "github:mattermost/marked#8214e10918264fb88cec474196023949f7cb4b30",
"mattermost-redux": "github:mattermost/mattermost-redux#66314024377668f3782e4c3a2df262ededa3a840",
"moment-timezone": "0.5.27",
"pdfjs-dist": "2.0.489",
Expand Down
33 changes: 33 additions & 0 deletions utils/markdown/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {format} from './index';

describe('format', () => {
test('should highlight code without space before language', () => {
const output = format(`~~~diff
- something
+ something else
~~~`);

expect(output).toContain('<span class="post-code__language">Diff</span>');
expect(output).toContain('<code class="hljs hljs-ln">');
});

test('should highlight code with space before language', () => {
const output = format(`~~~ diff
- something
+ something else
~~~`);

expect(output).toContain('<span class="post-code__language">Diff</span>');
expect(output).toContain('<code class="hljs hljs-ln">');
});

test('should not highlight code with an invalid language', () => {
const output = format(`~~~garbage
~~~`);

expect(output).not.toContain('<span class="post-code__language">');
});
});

0 comments on commit 6745a6e

Please sign in to comment.