Browse Source

Fixes #849 - uses vscode's markdown escaping regex

main
Eric Amodio 5 years ago
parent
commit
6f13cecfeb
3 changed files with 20 additions and 10 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -10
      src/git/formatters/commitFormatter.ts
  3. +18
    -0
      src/system/string.ts

+ 1
- 0
CHANGELOG.md View File

@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#849](https://github.com/eamodio/vscode-gitlens/issues/849) - Extra backslash in the hovers blame detail's link
- Fixes [#847](https://github.com/eamodio/vscode-gitlens/issues/847) - Refresh button on Compare With Branch view is not working
- Fixes [#842](https://github.com/eamodio/vscode-gitlens/issues/842) - List of changed files in comparison to working tree only shows changed files in comparison to HEAD
- Fixes [#828](https://github.com/eamodio/vscode-gitlens/issues/828) - Version comparison to show welcome message is not future proof — thanks to [PR #829](https://github.com/eamodio/vscode-gitlens/pull/829) by Arunprasad Rajkumar ([@arajkumar](https://github.com/arajkumar))

+ 1
- 10
src/git/formatters/commitFormatter.ts View File

@ -19,9 +19,6 @@ import { emojify } from '../../emojis';
const emptyStr = '';
const escapeMarkdownRegex = /[`>#*_\-+.]/g;
// const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___';
const markdownHeaderReplacement = `${GlyphChars.ZeroWidthSpace}===`;
const hasTokenRegexMap = new Map<string, RegExp>();
export interface CommitFormatOptions extends FormatOptions {
@ -317,13 +314,7 @@ export class CommitFormatter extends Formatter {
}
}
return `\n> ${message
// Escape markdown
.replace(escapeMarkdownRegex, '\\$&')
// Escape markdown header (since the above regex won't match it)
.replace(/^===/gm, markdownHeaderReplacement)
// Keep under the same block-quote but with line breaks
.replace(/\n/g, '\t\n> ')}`;
return `\n> ${Strings.escapeMarkdown(message, { quoted: true })}`;
}
get sha() {

+ 18
- 0
src/system/string.ts View File

@ -15,6 +15,24 @@ export namespace Strings {
Backslash = 92
}
const escapeMarkdownRegex = /[\\`*_{}[\]()#+\-.!]/g;
const escapeMarkdownHeaderRegex = /^===/gm;
// const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___';
const markdownQuotedRegex = /\n/g;
export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): string {
s = s
// Escape markdown
.replace(escapeMarkdownRegex, '\\$&')
// Escape markdown header (since the above regex won't match it)
.replace(escapeMarkdownHeaderRegex, '\u200b===');
if (!options.quoted) return s;
// Keep under the same block-quote but with line breaks
return s.replace(markdownQuotedRegex, '\t\n> ');
}
export function getCommonBase(s1: string, s2: string, delimiter: string) {
let char;
let index = 0;

Loading…
Cancel
Save