Skip to content

Commit

Permalink
Fix code preview on attachments (mattermost#4291)
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino authored and jfrerich committed Nov 22, 2019
1 parent 4aaddb7 commit 22857e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion utils/markdown/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class Renderer extends marked.Renderer {
// if we have to apply syntax highlighting AND highlighting of search terms, create two copies
// of the code block, one with syntax highlighting applied and another with invisible text, but
// search term highlighting and overlap them
const content = SyntaxHighlighting.highlight(usedLanguage, code);
const content = SyntaxHighlighting.highlight(usedLanguage, code, true);
let searchedContent = '';

if (this.formattingOptions.searchPatterns) {
Expand Down
7 changes: 5 additions & 2 deletions utils/syntax_highlighting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ function formatHighLight(code: string) {
return code;
}

export function highlight(lang: string, code: string) {
export function highlight(lang: string, code: string, addLineNumbers = false) {
const language = getLanguageFromNameOrAlias(lang);

if (language) {
try {
const codeValue = hlJS.highlight(language, code).value;
return formatHighLight(codeValue);
if (addLineNumbers) {
return formatHighLight(codeValue);
}
return codeValue;
} catch (e) {
// fall through if highlighting fails and handle below
}
Expand Down

0 comments on commit 22857e9

Please sign in to comment.