12
12
13
13
import
14
14
ast, strutils, strtabs, options, msgs, os, idents,
15
- wordrecg, syntaxes, renderer, lexer, packages / docutils / rstast,
15
+ wordrecg, syntaxes, renderer, lexer,
16
16
packages/ docutils/ rst, packages/ docutils/ rstgen,
17
17
json, xmltree, trees, types,
18
18
typesrenderer, astalgo, lineinfos, intsets,
19
19
pathutils, tables, nimpaths, renderverbatim, osproc
20
+ import packages/ docutils/ rstast except FileIndex , TLineInfo
20
21
21
22
from uri import encodeUrl
22
23
from std/ private/ globs import nativeToUnixPath
@@ -159,17 +160,18 @@ template declareClosures =
159
160
case msgKind
160
161
of meCannotOpenFile: k = errCannotOpenFile
161
162
of meExpected: k = errXExpected
162
- of meGridTableNotImplemented: k = errGridTableNotImplemented
163
- of meMarkdownIllformedTable: k = errMarkdownIllformedTable
164
- of meNewSectionExpected: k = errNewSectionExpected
165
- of meGeneralParseError: k = errGeneralParseError
166
- of meInvalidDirective: k = errInvalidDirectiveX
167
- of meInvalidRstField: k = errInvalidRstField
168
- of meFootnoteMismatch: k = errFootnoteMismatch
169
- of mwRedefinitionOfLabel: k = warnRedefinitionOfLabel
170
- of mwUnknownSubstitution: k = warnUnknownSubstitutionX
171
- of mwUnsupportedLanguage: k = warnLanguageXNotSupported
172
- of mwUnsupportedField: k = warnFieldXNotSupported
163
+ of meGridTableNotImplemented: k = errRstGridTableNotImplemented
164
+ of meMarkdownIllformedTable: k = errRstMarkdownIllformedTable
165
+ of meNewSectionExpected: k = errRstNewSectionExpected
166
+ of meGeneralParseError: k = errRstGeneralParseError
167
+ of meInvalidDirective: k = errRstInvalidDirectiveX
168
+ of meInvalidField: k = errRstInvalidField
169
+ of meFootnoteMismatch: k = errRstFootnoteMismatch
170
+ of mwRedefinitionOfLabel: k = warnRstRedefinitionOfLabel
171
+ of mwUnknownSubstitution: k = warnRstUnknownSubstitutionX
172
+ of mwBrokenLink: k = warnRstBrokenLink
173
+ of mwUnsupportedLanguage: k = warnRstLanguageXNotSupported
174
+ of mwUnsupportedField: k = warnRstFieldXNotSupported
173
175
of mwRstStyle: k = warnRstStyle
174
176
{.gcsafe .}:
175
177
globalError (conf, newLineInfo (conf, AbsoluteFile filename, line, col), k, arg)
@@ -182,11 +184,9 @@ template declareClosures =
182
184
183
185
proc parseRst (text, filename: string ,
184
186
line, column: int ,
185
- rstOptions: RstParseOptions ;
186
187
conf: ConfigRef , sharedState: PRstSharedState ): PRstNode =
187
188
declareClosures ()
188
- result = rstParsePass1 (text, filename, line, column, rstOptions,
189
- sharedState)
189
+ result = rstParsePass1 (text, line, column, sharedState)
190
190
191
191
proc getOutFile2 (conf: ConfigRef ; filename: RelativeFile ,
192
192
ext: string , guessTarget: bool ): AbsoluteFile =
@@ -202,20 +202,22 @@ proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
202
202
proc isLatexCmd (conf: ConfigRef ): bool = conf.cmd in {cmdRst2tex, cmdDoc2tex}
203
203
204
204
proc newDocumentor * (filename: AbsoluteFile ; cache: IdentCache ; conf: ConfigRef ,
205
- outExt: string = HtmlExt , module: PSym = nil ): PDoc =
205
+ outExt: string = HtmlExt , module: PSym = nil ,
206
+ isPureRst = false ): PDoc =
206
207
declareClosures ()
207
208
new (result )
208
209
result .module = module
209
210
result .conf = conf
210
211
result .cache = cache
211
212
result .outDir = conf.outDir.string
212
- const options = {roSupportRawDirective, roSupportMarkdown,
213
- roPreferMarkdown, roNimFile}
213
+ result .isPureRst = isPureRst
214
+ var options= {roSupportRawDirective, roSupportMarkdown, roPreferMarkdown}
215
+ if not isPureRst: options.incl roNimFile
214
216
result .sharedState = newRstSharedState (
215
217
options, filename.string ,
216
218
docgenFindFile, compilerMsgHandler)
217
219
initRstGenerator (result [], (if conf.isLatexCmd: outLatex else : outHtml),
218
- conf.configVars, filename.string , options,
220
+ conf.configVars, filename.string ,
219
221
docgenFindFile, compilerMsgHandler)
220
222
221
223
if conf.configVars.hasKey (" doc.googleAnalytics" ):
@@ -299,8 +301,7 @@ proc genComment(d: PDoc, n: PNode): PRstNode =
299
301
result = parseRst (n.comment, toFullPath (d.conf, n.info),
300
302
toLinenumber (n.info),
301
303
toColumn (n.info) + DocColOffset ,
302
- d.options, d.conf,
303
- d.sharedState)
304
+ d.conf, d.sharedState)
304
305
305
306
proc genRecCommentAux (d: PDoc , n: PNode ): PRstNode =
306
307
if n == nil : return nil
@@ -1123,6 +1124,9 @@ proc generateDoc*(d: PDoc, n, orig: PNode, docFlags: DocFlags = kDefault) =
1123
1124
1124
1125
proc finishGenerateDoc * (d: var PDoc ) =
1125
1126
# # Perform 2nd RST pass for resolution of links/footnotes/headings...
1127
+ # copy file map `filenames` to ``rstgen.nim`` for its warnings
1128
+ d.filenames = d.sharedState.filenames
1129
+
1126
1130
# Main title/subtitle are allowed only in the first RST fragment of document
1127
1131
var firstRst = PRstNode (nil )
1128
1132
for fragment in d.modDescPre:
@@ -1417,14 +1421,10 @@ proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
1417
1421
proc commandRstAux (cache: IdentCache , conf: ConfigRef ;
1418
1422
filename: AbsoluteFile , outExt: string ) =
1419
1423
var filen = addFileExt (filename, " txt" )
1420
- var d = newDocumentor (filen, cache, conf, outExt)
1421
-
1422
- d.isPureRst = true
1424
+ var d = newDocumentor (filen, cache, conf, outExt, isPureRst = true )
1423
1425
let rst = parseRst (readFile (filen.string ), filen.string ,
1424
1426
line= LineRstInit , column= ColRstInit ,
1425
- {roSupportRawDirective, roSupportMarkdown,
1426
- roPreferMarkdown}, conf,
1427
- d.sharedState)
1427
+ conf, d.sharedState)
1428
1428
d.modDescPre = @ [ItemFragment (isRst: true , rst: rst)]
1429
1429
finishGenerateDoc (d)
1430
1430
writeOutput (d)
0 commit comments