Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rst test check messages (fix #17280) #17338

Merged
merged 6 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/packages/docutils/rst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
## .. _Sphinx directives: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html

import
os, strutils, rstast, algorithm, lists, sequtils
os, strutils, rstast, std/enumutils, algorithm, lists, sequtils

type
RstParseOption* = enum ## options for the RST parser
Expand Down Expand Up @@ -487,7 +487,7 @@ template nextTok(p: RstParser): Token = p.tok[p.idx + 1]

proc whichMsgClass*(k: MsgKind): MsgClass =
## returns which message class `k` belongs to.
case ($k)[1]
case k.symbolName[1]
of 'e', 'E': result = mcError
of 'w', 'W': result = mcWarning
of 'h', 'H': result = mcHint
Expand Down Expand Up @@ -1954,25 +1954,31 @@ proc parseEnumList(p: var RstParser): PRstNode =
if match(p, p.idx, wildcards[w]): break
inc w
assert w < wildcards.len

proc checkAfterNewline(p: RstParser, report: bool): bool =
timotheecour marked this conversation as resolved.
Show resolved Hide resolved
## If no indentation on the next line then parse as a normal paragraph
## according to the RST spec. And report a warning with suggestions
let j = tokenAfterNewline(p, start=p.idx+1)
let requiredIndent = p.tok[p.idx+wildToken[w]].col
if p.tok[j].kind notin {tkIndent, tkEof} and
p.tok[j].col < p.tok[p.idx+wildToken[w]].col and
p.tok[j].col < requiredIndent and
(p.tok[j].col > col or
(p.tok[j].col == col and not match(p, j, wildcards[w]))):
if report:
let n = p.line + p.tok[j].line
let msg = "\n" & """
not enough indentation on line $2
(if it's continuation of enumeration list),
(should be at column $3 if it's a continuation of enum. list),
or no blank line after line $1 (if it should be the next paragraph),
or no escaping \ at the beginning of line $1
(if lines $1..$2 are a normal paragraph, not enum. list)""".
unindent(8)
rstMessage(p, mwRstStyle, msg % [$(n-1), $n])
rstMessage(p, mwRstStyle, msg % [$(n-1), $n, $(p.col+requiredIndent+1)],
p.tok[j].line, p.tok[j].col)
result = false
else:
result = true

if not checkAfterNewline(p, report = true):
return nil
result = newRstNodeA(p, rnEnumList)
Expand Down
10 changes: 5 additions & 5 deletions lib/packages/docutils/rstgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,8 @@ $content
# ---------- forum ---------------------------------------------------------

proc rstToHtml*(s: string, options: RstParseOptions,
config: StringTableRef): string =
config: StringTableRef, line=1, column=1,
msgHandler: MsgHandler = rst.defaultMsgHandler): string =
## Converts an input rst string into embeddable HTML.
##
## This convenience proc parses any input string using rst markup (it doesn't
Expand All @@ -1503,11 +1504,10 @@ proc rstToHtml*(s: string, options: RstParseOptions,

const filen = "input"
var d: RstGenerator
initRstGenerator(d, outHtml, config, filen, options, myFindFile,
rst.defaultMsgHandler)
initRstGenerator(d, outHtml, config, filen, options, myFindFile, msgHandler)
var dummyHasToc = false
var rst = rstParse(s, filen, line=LineRstInit, column=ColRstInit,
timotheecour marked this conversation as resolved.
Show resolved Hide resolved
dummyHasToc, options)
var rst = rstParse(s, filen, line=line, column=column,
dummyHasToc, options, myFindFile, msgHandler)
result = ""
renderRstToOut(d, rst, result)

Expand Down
Loading