Skip to content

Commit 75f7a83

Browse files
committed
smart squotes and apostrophe
1 parent f7ea41a commit 75f7a83

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-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: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ 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]>
12-
" Version: 5.0
13+
" Version: 5.1
1314

1415
" Configuration: {{{1
1516
"
@@ -223,6 +224,14 @@ endif
223224

224225
" Syntax Rules: {{{1
225226

227+
" corrects distracting conceal (ligature) background colors, blue makes
228+
" it obvious that the character is a ligature instead of an actual Unicode
229+
" character since both can exist in the same file
230+
hi Conceal ctermbg=none ctermfg=Blue
231+
232+
" preferable link color to underlining
233+
hi link pandocDelimitedCodeBlock pandocNoFormatted
234+
226235
" Embeds: {{{2
227236

228237
" HTML: {{{3
@@ -368,11 +377,11 @@ call s:WithConceal('strikeout', 'syn match pandocStrikeoutMark /\~\~/ contained
368377
" }}}2
369378

370379
" Headers: {{{2
371-
syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
380+
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
372381
syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@<!#\+\(\s*.*$\)\@=\)/ contained containedin=pandocAtxHeader
373382
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
383+
syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,pandocEllipses,@Spell,pandocAmpersandEscape
384+
syn match pandocSetexHeader /^.\+\n[-]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,pandocBeginQuote,pandocEndQuote,pandocBeginSQuote,pandocEndSQuote,pandocApostrophe,pandocEllipses,@Spell,pandocAmpersandEscape
376385
syn match pandocHeaderAttr /{.*}/ contained containedin=pandocAtxHeader,pandocSetexHeader
377386
syn match pandocHeaderID /#[-_:.[:lower:][:upper:]]*/ contained containedin=pandocHeaderAttr
378387
" }}}2
@@ -452,12 +461,12 @@ call s:WithConceal('abbrev', 'syn match pandocAbbreviationTail /\]/ contained co
452461
syn match pandocFootnoteID /\[\^[^\]]\+\]/ nextgroup=pandocFootnoteDef
453462

454463
" 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
464+
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
456465
call s:WithConceal('footnote', 'syn match pandocFootnoteDefHead /\^\[/ contained containedin=pandocFootnoteDef', 'conceal cchar='.s:cchars['footnote'])
457466
call s:WithConceal('footnote', 'syn match pandocFootnoteDefTail /\]/ contained containedin=pandocFootnoteDef', 'conceal')
458467

459468
" 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
469+
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
461470
syn match pandocFootnoteBlockSeparator /:/ contained containedin=pandocFootnoteBlock
462471
syn match pandocFootnoteID /\[\^.\{-}\]/ contained containedin=pandocFootnoteBlock
463472
call s:WithConceal('footnote', 'syn match pandocFootnoteIDHead /\[\^/ contained containedin=pandocFootnoteID', 'conceal cchar='.s:cchars['footnote'])
@@ -522,6 +531,19 @@ if &encoding ==# 'utf-8'
522531
call s:WithConceal('quotes', 'syn match pandocEndQuote /\(\>[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=”')
523532
endif
524533
" }}}3
534+
"
535+
" Apostrophes: {{{3
536+
if &encoding ==# 'utf-8'
537+
call s:WithConceal('apostrophes', 'syn match pandocApostrophe /[*~_\n[:space:]]\@<!''/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=’')
538+
endif
539+
" }}}3
540+
541+
" Single Quotes: {{{3
542+
if &encoding ==# 'utf-8'
543+
call s:WithConceal('squotes', 'syn match pandocBeginSQuote /[_*\n[:space:]]\@<=''\</ containedin=pandocEmphasis,pandocStrong,pandocListItem,pandocListItemContinuation,pandocUListItem display', 'conceal cchar=‘')
544+
call s:WithConceal('squotes', 'syn match pandocEndSQuote /\(\>[[:punct:]]*\)\@<=''[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=’')
545+
endif
546+
" }}}3
525547

526548
" Hrule: {{{3
527549
syn match pandocHRule /^\s*\([*\-_]\)\s*\%(\1\s*\)\{2,}$/ display

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)