Skip to content

Commit efe6a9a

Browse files
rwxrobalerque
authored andcommitted
Fix smart quotes and apostrophe
1 parent f7ea41a commit efe6a9a

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

doc/pandoc-syntax.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ CONFIGURATION *vim-pandoc-syntax-configuration*
3737
- dashes
3838
- ellipses
3939
- quotes
40+
- squotes
41+
- apostrophe
4042
- inlinecode
4143

4244
To review what are the rules for, look for the call to |s:WithConceal| in

syntax/pandoc.vim

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ scriptencoding utf-8
88
" Maintainer: Caleb Maclennan <[email protected]>
99
" Contributor: David Sanson <[email protected]>
1010
" Contributor: Jorge Israel Peña <[email protected]>
11+
" Contributor: Rob Muhlestein (twitch.tv/rwxrob) <[email protected]>
1112
" OriginalAuthor: Jeremy Schultz <[email protected]>
1213
" Version: 5.0
1314

@@ -264,7 +265,7 @@ syn match pandocTitleBlockTitle /\%^%.*\n/ contained containedin=pandocTitleBloc
264265
" }}}2
265266

266267
" Blockquotes: {{{2
267-
syn match pandocBlockQuote /^\s\{,3}>.*\n\(.*\n\@1<!\n\)*/ contains=@Spell,pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted,pandocAmpersandEscape,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion skipnl
268+
syn match pandocBlockQuote /^\s\{,3}>.*\n\(.*\n\@1<!\n\)*/ contains=@Spell,pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted,pandocAmpersandEscape,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe skipnl
268269
syn match pandocBlockQuoteMark /\_^\s\{,3}>/ contained containedin=pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted
269270
" }}}2
270271

@@ -368,11 +369,11 @@ call s:WithConceal('strikeout', 'syn match pandocStrikeoutMark /\~\~/ contained
368369
" }}}2
369370

370371
" Headers: {{{2
371-
syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
372+
syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,pandocEllipses,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
372373
syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@<!#\+\(\s*.*$\)\@=\)/ contained containedin=pandocAtxHeader
373374
call s:WithConceal('atx', 'syn match pandocAtxStart /#/ contained containedin=pandocAtxHeaderMark', 'conceal cchar='.s:cchars['atx'])
374-
syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape
375-
syn match pandocSetexHeader /^.\+\n[-]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape
375+
syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,pandocEllipses,@Spell,pandocAmpersandEscape
376+
syn match pandocSetexHeader /^.\+\n[-]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,pandocEllipses,@Spell,pandocAmpersandEscape
376377
syn match pandocHeaderAttr /{.*}/ contained containedin=pandocAtxHeader,pandocSetexHeader
377378
syn match pandocHeaderID /#[-_:.[:lower:][:upper:]]*/ contained containedin=pandocHeaderAttr
378379
" }}}2
@@ -452,12 +453,12 @@ call s:WithConceal('abbrev', 'syn match pandocAbbreviationTail /\]/ contained co
452453
syn match pandocFootnoteID /\[\^[^\]]\+\]/ nextgroup=pandocFootnoteDef
453454

454455
" Inline footnotes
455-
syn region pandocFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocStrongEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocEllipses,pandocBeginQuote,pandocEndQuote,@Spell,pandocAmpersandEscape skipnl keepend
456+
syn region pandocFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocStrongEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,@Spell,pandocAmpersandEscape skipnl keepend
456457
call s:WithConceal('footnote', 'syn match pandocFootnoteDefHead /\^\[/ contained containedin=pandocFootnoteDef', 'conceal cchar='.s:cchars['footnote'])
457458
call s:WithConceal('footnote', 'syn match pandocFootnoteDefTail /\]/ contained containedin=pandocFootnoteDef', 'conceal')
458459

459460
" regular footnotes
460-
syn region pandocFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocNewLine,pandocStrongEmphasis,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocAmpersandEscape,@Spell skipnl
461+
syn region pandocFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocNewLine,pandocStrongEmphasis,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostophe,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocAmpersandEscape,@Spell skipnl
461462
syn match pandocFootnoteBlockSeparator /:/ contained containedin=pandocFootnoteBlock
462463
syn match pandocFootnoteID /\[\^.\{-}\]/ contained containedin=pandocFootnoteBlock
463464
call s:WithConceal('footnote', 'syn match pandocFootnoteIDHead /\[\^/ contained containedin=pandocFootnoteID', 'conceal cchar='.s:cchars['footnote'])
@@ -523,6 +524,19 @@ if &encoding ==# 'utf-8'
523524
endif
524525
" }}}3
525526

527+
" Apostrophes: {{{3
528+
if &encoding ==# 'utf-8'
529+
call s:WithConceal('apostrophes', 'syn match pandocApostrophe /[*~_\n[:space:]]\@<!''/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=’')
530+
endif
531+
" }}}3
532+
533+
" Single Quotes: {{{3
534+
if &encoding ==# 'utf-8'
535+
call s:WithConceal('squotes', 'syn match pandocBeginSQuote /[_*\n[:space:]]\@<=''\</ containedin=pandocEmphasis,pandocStrong,pandocListItem,pandocListItemContinuation,pandocUListItem display', 'conceal cchar=‘')
536+
call s:WithConceal('squotes', 'syn match pandocEndSQuote /\(\>[[:punct:]]*\)\@<=''[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=’')
537+
endif
538+
" }}}3
539+
526540
" Hrule: {{{3
527541
syn match pandocHRule /^\s*\([*\-_]\)\s*\%(\1\s*\)\{2,}$/ display
528542
" }}}3

tests/smart.pdc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# smart punctuation
2+
3+
# Ellipses ...
4+
5+
Ellipses ...
6+
----------
7+
8+
Ellipses ...
9+
==========
10+
11+
And then there was ...
12+
13+
Blah ... blah.
14+
15+
... and yet.
16+
...and yet.
17+
18+
# "Foo" is a thing
19+
20+
A "Foo" is a thing
21+
------------------
22+
23+
A "Foo" is a thing
24+
==================
25+
26+
Just some "foo" here.
27+
Are you a "foo"?
28+
29+
"Foo"
30+
*"Foo"*
31+
**"Foo"**
32+
_"Foo"_
33+
__"Foo"__
34+
~~"Foo"~~
35+
36+
# 'Bar'
37+
38+
'Bar'
39+
-----
40+
41+
'Bar'
42+
=====
43+
44+
Just some 'bar' here.
45+
Are you a 'bar'?
46+
47+
'Bar'
48+
*'Bar'*
49+
**'Bar'**
50+
_'Bar'_
51+
__'Bar'__
52+
~~'Bar'~~
53+
54+
# I'd Really Like to Know
55+
56+
I'd Really Like to Know
57+
-----------------------
58+
59+
I'd Really Like to Know
60+
=======================
61+
62+
I'd
63+
'cuz

0 commit comments

Comments
 (0)