Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c059abf

Browse files
ashfinallpil
authored andcommitted
refine rst snippets
1 parent 7b6991e commit c059abf

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed

UltiSnips/rst.snippets

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,37 @@ from collections import Counter
1414
1515
from vimsnippets import complete
1616
17-
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
18-
TEXT_ROLES = ['emphasis','literal','code','math',
19-
'pep-reference','rfc-reference',
20-
'strong','subscript','superscript',
21-
'title-reference','raw']
17+
# http://docutils.sourceforge.net/docs/ref/rst/roles.html
18+
TEXT_ROLES = ['emphasis', 'literal', 'code', 'math',
19+
'pep-reference', 'rfc-reference',
20+
'strong', 'subscript', 'superscript',
21+
'title-reference', 'raw']
2222
TEXT_ROLES_REGEX = r'\.\.\srole::?\s(w+)'
2323
24-
#http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions
24+
# http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions
2525
SPECIFIC_ADMONITIONS = ["attention", "caution", "danger",
2626
"error", "hint", "important", "note",
2727
"tip", "warning"]
28-
#http://docutils.sourceforge.net/docs/ref/rst/directives.html
29-
DIRECTIVES = ['topic','sidebar','math','epigraph',
30-
'parsed-literal','code','highlights',
31-
'pull-quote','compound','container','table','csv-table',
32-
'list-table','class','sectnum',
33-
'role','default-role','unicode',
34-
'raw']
28+
# http://docutils.sourceforge.net/docs/ref/rst/directives.html
29+
DIRECTIVES = ['code', 'contents', 'admonition', 'table', 'csv-table', 'list-table',
30+
'class', 'container', 'sidebar', 'topic', 'title',
31+
'role', 'default-role', 'raw']
3532
36-
NONE_CONTENT_DIRECTIVES = ['rubric', 'contents', 'header',
37-
'footer', 'date', 'include', 'title']
33+
# DIRECTIVES_WITHOUT_TITLE means directive arguments equal None
34+
DIRECTIVES_WITHOUT_TITLE = ['math', 'meta', 'parsed-literal', 'line-block',
35+
'header', 'compound', 'highlights', 'pull-quote',
36+
'footer', 'epigraph', 'rubric', 'sectnum']
3837
3938
INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include']
39+
40+
# Directives for Subsubsection Definition
41+
DIRECTIVES_FOR_SUBSTITUTION = ['replace', 'unicode', 'date']
42+
4043
# CJK chars
4144
# http://stackoverflow.com/questions/2718196/find-all-chinese-text-in-a-string-using-python-and-regex
4245
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
4346
44-
#http://www.pygal.org/en/stable/documentation/types/index.html
47+
# http://www.pygal.org/en/stable/documentation/types/index.html
4548
CHART_TYPES = ["Line", "StackedLine", "HorizontalLine", "Bar", "StackedBar", "HorizontalBar", "Histogram", "XY", "DateLine", "TimeLine", "TimeDeltaLine", "DateTimeLine", "Pie", "Radar", "Box", "Dot", "Funnel", "Gauge", "SolidGauge", "Pyramid", "Treemap"]
4649
4750
def has_cjk(s):
@@ -264,23 +267,30 @@ snippet di "Directives" b
264267
$0
265268
endsnippet
266269

267-
snippet nd "None Content Directives" b
268-
.. $1`!p snip.rv=complete(t[1], NONE_CONTENT_DIRECTIVES)`:: $2
270+
snippet dt "Directives without title" b
271+
.. $1`!p snip.rv=complete(t[1], DIRECTIVES_WITHOUT_TITLE)`::
272+
273+
${2:${VISUAL:Content}}
274+
$0
275+
endsnippet
276+
277+
snippet ds "Directives for subscription" b
278+
.. |$1| $2`!p snip.rv=complete(t[2], DIRECTIVES_FOR_SUBSTITUTION)`:: ${3:Content}
269279
$0
270280
endsnippet
271281

272282
snippet sa "Specific Admonitions" b
273-
.. $1`!p snip.rv =complete(t[1], SPECIFIC_ADMONITIONS)`::
283+
.. $1`!p snip.rv =complete(t[1], SPECIFIC_ADMONITIONS)`:: $2
274284

275-
${2:${VISUAL:Content}}
285+
${3:${VISUAL:Content}}
276286

277287
$0
278288
endsnippet
279289

280-
#it will be trigger at start of line or after a word
290+
# it will be trigger at start of line or after a word
281291
snippet ro "Text Roles" w
282292
\ :$1`!p snip.rv=complete(t[1],
283-
TEXT_ROLES+look_up_directives(TEXT_ROLES_REGEX,
293+
TEXT_ROLES+look_up_directives(TEXT_ROLES_REGEX,
284294
path))`:\`$2\`\
285295
endsnippet
286296

@@ -306,7 +316,7 @@ snippet chart "Pygal chart for Nikola" b
306316
.. chart:: $1`!p snip.rv=complete(t[1], CHART_TYPES)`
307317
:title: '${2:Browser usage evolution (in %)}'
308318
:x_labels: [${3:"2002", "2003", "2004", "2005", "2006", "2007"}]
309-
319+
310320
'Firefox', [None, None, 0, 16.6, 25, 31]
311321
'Chrome', [None, None, None, None, None, None]
312322
'IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6]
@@ -323,4 +333,5 @@ snippet sid "SideBar" b
323333

324334
${2:${VISUAL:SideBar Content}}
325335
endsnippet
326-
# vim:ft=snippets:
336+
337+
# vim:set list noet sts=0 sw=4 ts=4:

snippets/rst.snippets

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ snippet -
1919
${0}
2020
#some directive
2121
snippet img:
22-
.. |${0:alias}| image:: ${1:img}
22+
.. |${1:alias}| image:: ${0:img}
2323
snippet fig:
2424
.. figure:: ${1:img}
25-
:alt: ${0:alter text}
25+
:alt: ${2:alter text}
26+
27+
$0
28+
snippet con:
29+
.. contents:: ${1:Table of Contents}
2630

27-
$2
28-
snippet cont:
29-
.. contents::
3031
${0:content}
31-
snippet code:
32+
snippet cod:
3233
.. code:: ${1:type}
3334

3435
${0:write some code}
@@ -65,34 +66,36 @@ snippet tod:
6566
.. todo::
6667
${0}
6768
snippet lis:
68-
.. list-table:: ${0:Title}
69+
.. list-table:: ${1:Title}
6970
:header-rows: 1
70-
:stub-columns: 1
71+
:stub-columns: 0
7172

72-
* - x1,y1
73-
- x2,y1
74-
- x3,y1
75-
* - x1,y2
76-
- x2,y2
77-
- x3,y2
78-
* - x1,y3
79-
- x2,y3
80-
- x3,y3
73+
* - ${0:R1C1}
74+
- R1C2
75+
* - R2C1
76+
- R2C2
77+
snippet csv:
78+
.. csv-table:: ${1:Title}
79+
:header-rows: 1
80+
:stub-columns: 0
8181

82+
${0:R1C1}, R1C2
83+
R2C1, R2C2
8284
snippet toc:
8385
.. toctree::
8486
:maxdepth: 2
8587

8688
${0}
8789
snippet dow:
88-
:download:\`${0:text} <${1:path}>\`
90+
:download:\`${1:text} <${0:path}>\`
8991
snippet ref:
90-
:ref:\`${0:text} <${1:path}>\`
92+
:ref:\`${1:text} <${0:path}>\`
9193
snippet doc:
92-
:doc:`${0:text} <${1:path}>`
94+
:doc:\`${1:text} <${0:path}>\`
9395
# CJK optimize, CJK has no space between charaters
9496
snippet *c
9597
\ *${1:Emphasis}*\ ${0}
9698
snippet **c
9799
\ **${1:Strong emphasis}**\ ${0}
98100

101+
# vim:set list noet sts=0 sw=4 ts=4:

0 commit comments

Comments
 (0)