From 3f6541b30688fb721e16f0915588a76c67f9029a Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Tue, 31 Mar 2020 05:42:15 +0530 Subject: [PATCH] bugdown: Add 'none' as alias for no syntax highlighting in codeblocks. This is a precursor to #14404. --- tools/setup/lang.json | 3 +++ zerver/lib/bugdown/fenced_code.py | 7 +++++++ zerver/tests/test_bugdown.py | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/tools/setup/lang.json b/tools/setup/lang.json index d1faca3883..7fbe8a80e7 100644 --- a/tools/setup/lang.json +++ b/tools/setup/lang.json @@ -31,6 +31,7 @@ "matlab": 33, "mql": 9, "mql4": 9, + "none": 1, "objective-c": 35, "objectivec": 35, "objectpascal": 42, @@ -38,6 +39,7 @@ "perl": 40, "php": 44, "pl": 40, + "plain": 1, "prolog": 16, "python": 46, "quote": 50, @@ -45,6 +47,7 @@ "rb": 39, "ruby": 39, "rust": 8, + "text": 1, "sas": 30, "scala": 21, "scheme": 14, diff --git a/zerver/lib/bugdown/fenced_code.py b/zerver/lib/bugdown/fenced_code.py index 437bd134e9..6b1afb23e9 100644 --- a/zerver/lib/bugdown/fenced_code.py +++ b/zerver/lib/bugdown/fenced_code.py @@ -165,6 +165,11 @@ def generic_handler(processor: Any, output: MutableSequence[str], else: return CodeHandler(processor, output, fence, lang, run_content_validators) +def remap_language(lang: str) -> str: + if lang in ['none', 'noop', 'text', 'plain']: + return '' + return lang + def check_for_new_fence(processor: Any, output: MutableSequence[str], line: str, run_content_validators: Optional[bool]=False) -> None: m = FENCE_RE.match(line) @@ -172,6 +177,8 @@ def check_for_new_fence(processor: Any, output: MutableSequence[str], line: str, fence = m.group('fence') lang = m.group('lang') + lang = remap_language(lang) + handler = generic_handler(processor, output, fence, lang, run_content_validators) processor.push(handler) else: diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index 0a45a5dd44..da165d2794 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -119,6 +119,10 @@ class FencedBlockPreprocessorTest(TestCase): '```c#', 'weirdchar()', '```', + '', + '``` none', + 'no-highlight()', + '```', '' ] expected = [ @@ -133,6 +137,10 @@ class FencedBlockPreprocessorTest(TestCase): '', '**c#:weirdchar()**', '', + '', + '', + '**:no-highlight()**', + '', '' ] lines = processor.run(markdown)