Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
ece89370
Commit
ece89370
authored
8 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
[markdown mode] Make strong/em delimiting more CommonMark-compliant
Closes #4686
parent
5aa64cc4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mode/gfm/gfm.js
+0
-1
0 additions, 1 deletion
mode/gfm/gfm.js
mode/markdown/markdown.js
+30
-43
30 additions, 43 deletions
mode/markdown/markdown.js
mode/markdown/test.js
+12
-12
12 additions, 12 deletions
mode/markdown/test.js
with
42 additions
and
56 deletions
mode/gfm/gfm.js
+
0
−
1
View file @
ece89370
...
...
@@ -113,7 +113,6 @@ CodeMirror.defineMode("gfm", function(config, modeConfig) {
};
var
markdownConfig
=
{
underscoresBreakWords
:
false
,
taskLists
:
true
,
fencedCodeBlocks
:
'
```
'
,
strikethrough
:
true
...
...
This diff is collapsed.
Click to expand it.
mode/markdown/markdown.js
+
30
−
43
View file @
ece89370
...
...
@@ -35,10 +35,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if
(
modeCfg
.
maxBlockquoteDepth
===
undefined
)
modeCfg
.
maxBlockquoteDepth
=
0
;
// Should underscores in words open/close em/strong?
if
(
modeCfg
.
underscoresBreakWords
===
undefined
)
modeCfg
.
underscoresBreakWords
=
true
;
// Use `fencedCodeBlocks` to configure fenced code blocks. false to
// disable, string to specify a precise regexp that the fence should
// match, and true to allow three or more backticks or tildes (as
...
...
@@ -89,7 +85,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
,
setextHeaderRE
=
/^ *
(?:\={1,}
|-
{1,})\s
*$/
,
textRE
=
/^
[^
#!
\[\]
*_
\\
<>` "'(~
]
+/
,
fencedCodeRE
=
new
RegExp
(
"
^(
"
+
(
modeCfg
.
fencedCodeBlocks
===
true
?
"
~~~+|```+
"
:
modeCfg
.
fencedCodeBlocks
)
+
"
)[
\\
t]*([
\\
w+#
\
-]*)
"
);
"
)[
\\
t]*([
\\
w+#
\
-]*)
"
)
,
punctuation
=
/
[
!
\"
#$%&
\'
()*+,
\-\.\/
:;<=>?@
\[\\\]
^_`{|}~—
]
/
function
switchInline
(
stream
,
state
,
f
)
{
state
.
f
=
state
.
inline
=
f
;
...
...
@@ -375,9 +372,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return
getType
(
state
);
}
// Get sol() value now, before character is consumed
var
sol
=
stream
.
sol
();
var
ch
=
stream
.
next
();
// Matches link titles present on next line
...
...
@@ -387,7 +381,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if
(
ch
===
'
(
'
)
{
matchCh
=
'
)
'
;
}
matchCh
=
(
matchCh
+
''
).
replace
(
/
([
.?*+^
$
[
\]\\
(){}|-
])
/g
,
"
\\
$1
"
);
matchCh
=
(
matchCh
+
''
).
replace
(
/
([
.?*+^
\
[\]\\
(){}|-
])
/g
,
"
\\
$1
"
);
var
regex
=
'
^
\\
s*(?:[^
'
+
matchCh
+
'
\\\\
]+|
\\\\\\\\
|
\\\\
.)
'
+
matchCh
;
if
(
stream
.
match
(
new
RegExp
(
regex
),
true
))
{
return
tokenTypes
.
linkHref
;
...
...
@@ -499,41 +493,34 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if
(
ch
===
'
<
'
&&
stream
.
match
(
/^
\/\w
*
?
>/
))
{
state
.
md_inside
=
false
;
return
"
tag
"
;
}
var
ignoreUnderscore
=
false
;
if
(
!
modeCfg
.
underscoresBreakWords
)
{
if
(
ch
===
'
_
'
&&
stream
.
peek
()
!==
'
_
'
&&
stream
.
match
(
/
(\w)
/
,
false
))
{
var
prevPos
=
stream
.
pos
-
2
;
if
(
prevPos
>=
0
)
{
var
prevCh
=
stream
.
string
.
charAt
(
prevPos
);
if
(
prevCh
!==
'
_
'
&&
prevCh
.
match
(
/
(\w)
/
,
false
))
{
ignoreUnderscore
=
true
;
}
}
}
else
if
(
ch
===
"
*
"
||
ch
===
"
_
"
)
{
var
len
=
1
,
before
=
stream
.
pos
==
1
?
"
"
:
stream
.
string
.
charAt
(
stream
.
pos
-
2
)
while
(
len
<
3
&&
stream
.
eat
(
ch
))
len
++
var
after
=
stream
.
peek
()
||
"
"
// See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
var
leftFlanking
=
!
/
\s
/
.
test
(
after
)
&&
(
!
punctuation
.
test
(
after
)
||
/
\s
/
.
test
(
before
)
||
punctuation
.
test
(
before
))
var
rightFlanking
=
!
/
\s
/
.
test
(
before
)
&&
(
!
punctuation
.
test
(
before
)
||
/
\s
/
.
test
(
after
)
||
punctuation
.
test
(
after
))
var
setEm
=
null
,
setStrong
=
null
if
(
len
%
2
)
{
// Em
if
(
!
state
.
em
&&
leftFlanking
&&
(
ch
===
"
*
"
||
!
rightFlanking
||
punctuation
.
test
(
before
)))
setEm
=
true
else
if
(
state
.
em
==
ch
&&
rightFlanking
&&
(
ch
===
"
*
"
||
!
leftFlanking
||
punctuation
.
test
(
after
)))
setEm
=
false
}
}
if
(
ch
===
'
*
'
||
(
ch
===
'
_
'
&&
!
ignoreUnderscore
))
{
if
(
sol
&&
stream
.
peek
()
===
'
'
)
{
// Do nothing, surrounded by newline and space
}
else
if
(
state
.
strong
===
ch
&&
stream
.
eat
(
ch
))
{
// Remove STRONG
if
(
modeCfg
.
highlightFormatting
)
state
.
formatting
=
"
strong
"
;
var
t
=
getType
(
state
);
state
.
strong
=
false
;
return
t
;
}
else
if
(
!
state
.
strong
&&
stream
.
eat
(
ch
))
{
// Add STRONG
state
.
strong
=
ch
;
if
(
modeCfg
.
highlightFormatting
)
state
.
formatting
=
"
strong
"
;
return
getType
(
state
);
}
else
if
(
state
.
em
===
ch
)
{
// Remove EM
if
(
modeCfg
.
highlightFormatting
)
state
.
formatting
=
"
em
"
;
var
t
=
getType
(
state
);
state
.
em
=
false
;
return
t
;
}
else
if
(
!
state
.
em
)
{
// Add EM
state
.
em
=
ch
;
if
(
modeCfg
.
highlightFormatting
)
state
.
formatting
=
"
em
"
;
return
getType
(
state
);
if
(
len
>
1
)
{
// Strong
if
(
!
state
.
strong
&&
leftFlanking
&&
(
ch
===
"
*
"
||
!
rightFlanking
||
punctuation
.
test
(
before
)))
setStrong
=
true
else
if
(
state
.
strong
==
ch
&&
rightFlanking
&&
(
ch
===
"
*
"
||
!
leftFlanking
||
punctuation
.
test
(
after
)))
setStrong
=
false
}
if
(
setStrong
!=
null
||
setEm
!=
null
)
{
if
(
modeCfg
.
highlightFormatting
)
state
.
formatting
=
setEm
==
null
?
"
strong
"
:
setStrong
==
null
?
"
em
"
:
"
strong em
"
if
(
setEm
===
true
)
state
.
em
=
ch
if
(
setStrong
===
true
)
state
.
strong
=
ch
var
t
=
getType
(
state
)
if
(
setEm
===
false
)
state
.
em
=
false
if
(
setStrong
===
false
)
state
.
strong
=
false
return
t
}
}
else
if
(
ch
===
'
'
)
{
if
(
stream
.
eat
(
'
*
'
)
||
stream
.
eat
(
'
_
'
))
{
// Probably surrounded by spaces
...
...
This diff is collapsed.
Click to expand it.
mode/markdown/test.js
+
12
−
12
View file @
ece89370
...
...
@@ -381,28 +381,28 @@
MT
(
"
listAsteriskFormatting
"
,
"
[variable-2 * ][variable-2&em *foo*][variable-2 bar]
"
,
"
[variable-2 * ][variable-2&strong **foo**][variable-2 bar]
"
,
"
[variable-2 *
][variable-2&strong **
][variable-2&em&strong *foo**
][variable-2&em
*][variable-2 bar]
"
,
"
[variable-2 * ][variable-2&em&strong
**
*foo***][variable-2 bar]
"
,
"
[variable-2 * ][variable-2&comment `foo`][variable-2 bar]
"
);
// Formatting in lists (+)
MT
(
"
listPlusFormatting
"
,
"
[variable-2 + ][variable-2&em *foo*][variable-2 bar]
"
,
"
[variable-2 + ][variable-2&strong **foo**][variable-2 bar]
"
,
"
[variable-2 +
][variable-2&strong **
][variable-2&em&strong *foo**
][variable-2&em
*][variable-2 bar]
"
,
"
[variable-2 + ][variable-2&em&strong
**
*foo***][variable-2 bar]
"
,
"
[variable-2 + ][variable-2&comment `foo`][variable-2 bar]
"
);
// Formatting in lists (-)
MT
(
"
listDashFormatting
"
,
"
[variable-2 - ][variable-2&em *foo*][variable-2 bar]
"
,
"
[variable-2 - ][variable-2&strong **foo**][variable-2 bar]
"
,
"
[variable-2 -
][variable-2&strong **
][variable-2&em&strong *foo**
][variable-2&em
*][variable-2 bar]
"
,
"
[variable-2 - ][variable-2&em&strong
**
*foo***][variable-2 bar]
"
,
"
[variable-2 - ][variable-2&comment `foo`][variable-2 bar]
"
);
// Formatting in lists (1.)
MT
(
"
listNumberFormatting
"
,
"
[variable-2 1. ][variable-2&em *foo*][variable-2 bar]
"
,
"
[variable-2 2. ][variable-2&strong **foo**][variable-2 bar]
"
,
"
[variable-2 3.
][variable-2&strong **
][variable-2&em&strong *foo**
][variable-2&em
*][variable-2 bar]
"
,
"
[variable-2 3. ][variable-2&em&strong
**
*foo***][variable-2 bar]
"
,
"
[variable-2 4. ][variable-2&comment `foo`][variable-2 bar]
"
);
// Paragraph lists
...
...
@@ -605,7 +605,7 @@
"
[image&image-marker !][image&image-alt-text&link [[][image-alt-text&strong&image&link **alt text**][image&image-alt-text&link ]]][string&url (http://link.to/image.jpg)]
"
);
MT
(
"
imageEmStrong
"
,
"
[image&image-marker !][image&image-alt-text&link [[][image
-alt-text&image&strong&link **][image
&image-alt-text&em&strong&link *alt text**
][image&image-alt-text&em&link
*][image&image-alt-text&link ]]][string&url (http://link.to/image.jpg)]
"
);
"
[image&image-marker !][image&image-alt-text&link [[][image&image-alt-text&em&strong&link
**
*alt text***][image&image-alt-text&link ]]][string&url (http://link.to/image.jpg)]
"
);
// Inline link with title
MT
(
"
linkTitle
"
,
...
...
@@ -629,7 +629,7 @@
// Inline link with EmStrong
MT
(
"
linkEmStrong
"
,
"
[link [[][link&
strong **][link&
em&strong *foo**
][link&em
*][link ]]][string&url (http://example.com/)] bar
"
);
"
[link [[][link&em&strong
**
*foo***][link ]]][string&url (http://example.com/)] bar
"
);
// Image with title
MT
(
"
imageTitle
"
,
...
...
@@ -663,7 +663,7 @@
// Reference-style links with EmStrong
MT
(
"
linkReferenceEmStrong
"
,
"
[link [[][link&
strong **][link&
em&strong *foo**
][link&em
*][link ]]][string&url [[bar]]] hello
"
);
"
[link [[][link&em&strong
**
*foo***][link ]]][string&url [[bar]]] hello
"
);
// Reference-style links with optional space separator (per documentation)
// "You can optionally use a space to separate the sets of brackets"
...
...
@@ -757,7 +757,7 @@
"
foo[em *bar*]hello
"
);
MT
(
"
emInWordUnderscore
"
,
"
foo
[em
_bar_
]
hello
"
);
"
foo_bar_hello
"
);
// Per documentation: "...surround an * or _ with spaces, it’ll be
// treated as a literal asterisk or underscore."
...
...
@@ -766,11 +766,11 @@
"
foo [em _bar _ hello_] world
"
);
MT
(
"
emEscapedBySpaceOut
"
,
"
foo _ bar[em _hello_]world
"
);
"
foo _ bar
[em _hello_]
world
"
);
MT
(
"
emEscapedByNewline
"
,
"
foo
"
,
"
_ bar[em _hello_]world
"
);
"
_ bar
[em _hello_]
world
"
);
// Unclosed emphasis characters
// Instead of simply marking as EM / STRONG, it would be nice to have an
...
...
@@ -791,14 +791,14 @@
"
[em *foo][em&strong **bar*][strong hello**] world
"
);
MT
(
"
emStrongUnderscore
"
,
"
[em _foo][em&strong __bar_][strong hello__] world
"
);
"
[em _foo
][em&strong __bar_][strong
hello__] world
"
);
// "...same character must be used to open and close an emphasis span.""
MT
(
"
emStrongMixed
"
,
"
[em _foo][em&strong **bar*hello__ world]
"
);
MT
(
"
emStrongMixed
"
,
"
[em *foo][em&strong __bar_hello** world]
"
);
"
[em *foo
][em&strong __bar_hello** world]
"
);
MT
(
"
linkWithNestedParens
"
,
"
[link [[foo]]][string&url (bar(baz))]
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment