feat(ellipsis): add auto-ellipsis support

Three dots `...` are now converted automatically into an ellipsis
This commit is contained in:
Estevao Soares dos Santos 2017-10-24 17:06:08 +01:00
parent 084b819b14
commit 25f1978666
10 changed files with 71 additions and 5 deletions

13
dist/showdown.js vendored
View File

@ -2918,6 +2918,18 @@ showdown.subParser('detab', function (text, options, globals) {
return text;
});
showdown.subParser('ellipsis', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('ellipsis.before', text, options, globals);
text = text.replace(/\.\.\./g, '…');
text = globals.converter._dispatch('ellipsis.after', text, options, globals);
return text;
});
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
@ -3979,6 +3991,7 @@ showdown.subParser('spanGamut', function (text, options, globals) {
text = showdown.subParser('underline')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);
text = showdown.subParser('ellipsis')(text, options, globals);
// we need to hash HTML tags inside spans
text = showdown.subParser('hashHTMLSpans')(text, options, globals);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,11 @@
showdown.subParser('ellipsis', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('ellipsis.before', text, options, globals);
text = text.replace(/\.\.\./g, '…');
text = globals.converter._dispatch('ellipsis.after', text, options, globals);
return text;
});

View File

@ -24,6 +24,7 @@ showdown.subParser('spanGamut', function (text, options, globals) {
text = showdown.subParser('underline')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);
text = showdown.subParser('ellipsis')(text, options, globals);
// we need to hash HTML tags inside spans
text = showdown.subParser('hashHTMLSpans')(text, options, globals);

19
test/cases/ellipsis.html Normal file
View File

@ -0,0 +1,19 @@
<p>ellipsis in text…</p>
<p></p>
<ol>
<li>foo…</li>
<li>bar</li>
</ol>
<blockquote>
<p>ellipsis in blockquote…</p>
</blockquote>
<pre><code>ellipsis in code...
</code></pre>
<pre><code>ellipsis in code...
</code></pre>
<h1 id="ellipsisinheader">ellipsis in header…</h1>
<p>1…</p>
<ol>
<li>..</li>
</ol>
<p>1…</p>

22
test/cases/ellipsis.md Normal file
View File

@ -0,0 +1,22 @@
ellipsis in text...
...
1. foo...
2. bar
> ellipsis in blockquote...
```
ellipsis in code...
```
ellipsis in code...
# ellipsis in header...
1...
1. ..
1...

View File

@ -2,7 +2,7 @@
<li>foo<ul>
<li>bar</li></ul></li>
</ul>
<p>...</p>
<hr />
<ul>
<li>baz<ol>
<li>bazinga</li></ol></li>

View File

@ -1,7 +1,7 @@
* foo
* bar
...
---
* baz
1. bazinga