Skip to content
Snippets Groups Projects
Commit dea93740 authored by Hasan Karahan's avatar Hasan Karahan Committed by Marijn Haverbeke
Browse files

[rst] Emphasis and literal highlighting fix

Ensured that emphasis (weak & strong) plus literal syntax highlighting are rendered correctly even if the highlighted word is followed immediately by a non-word character (like an interpunction):

 * ```a word **strongly emphasised**?```;
 * ```a word *weakly emphasised*?```;
 * ```a word with ``literal emphasis``?```;

Further changed recognition order to `strong`, `weak`, `literal`, `number`, `positive`, `negative` and `link` to comply more with the reStructuredText spec (see http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#recognition-order).
parent 1121be6c
No related branches found
No related tags found
No related merge requests found
The MIT License
Copyright (c) 2013 Hasan Karahan
Copyright (c) 2013 Hasan Karahan <hasan.karahan81@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -494,6 +494,14 @@ CodeMirror.defineMode('rst-base', function (config) {
CodeMirror.defineMode('rst', function (config, options) {
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*/;
var rx_emphasis = /^\*[^\*\s](?:[^\*]*[^\*\s])?\*/;
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``/;
var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
var rx_negative = /^(?:\s\-[\d]+(?:[\.,]\d+)*)/;
var rx_uri_protocol = "[Hh][Tt][Tt][Pp][Ss]?://";
var rx_uri_domain = "(?:[\\d\\w.-]+)\\.(?:\\w{2,6})";
var rx_uri_path = "(?:/[\\d\\w\\#\\%\\&\\-\\.\\,\\/\\:\\=\\?\\~]+)*";
......@@ -501,33 +509,32 @@ CodeMirror.defineMode('rst', function (config, options) {
rx_uri_protocol + rx_uri_domain + rx_uri_path
);
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*(\s+|$)/;
var rx_emphasis = /^[^\*]\*[^\*\s](?:[^\*]*[^\*\s])?\*(\s+|$)/;
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``(\s+|$)/;
var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
var rx_negative = /^(?:\s\-[\d]+(?:[\.,]\d+)*)/;
var overlay = {
token: function (stream) {
if (stream.match(rx_uri)) return 'link';
if (stream.match(rx_strong)) return 'strong';
if (stream.match(rx_emphasis)) return 'em';
if (stream.match(rx_literal)) return 'string-2';
if (stream.match(rx_number)) return 'number';
if (stream.match(rx_positive)) return 'positive';
if (stream.match(rx_negative)) return 'negative';
if (stream.match(rx_strong) && stream.match (/\W+|$/, false))
return 'strong';
if (stream.match(rx_emphasis) && stream.match (/\W+|$/, false))
return 'em';
if (stream.match(rx_literal) && stream.match (/\W+|$/, false))
return 'string-2';
if (stream.match(rx_number))
return 'number';
if (stream.match(rx_positive))
return 'positive';
if (stream.match(rx_negative))
return 'negative';
if (stream.match(rx_uri))
return 'link';
while (stream.next() != null) {
if (stream.match(rx_uri, false)) break;
if (stream.match(rx_strong, false)) break;
if (stream.match(rx_emphasis, false)) break;
if (stream.match(rx_literal, false)) break;
if (stream.match(rx_number, false)) break;
if (stream.match(rx_positive, false)) break;
if (stream.match(rx_negative, false)) break;
if (stream.match(rx_uri, false)) break;
}
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment