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

Add rstgen.rstToJson #14712

Closed
wants to merge 1 commit into from
Closed

Add rstgen.rstToJson #14712

wants to merge 1 commit into from

Conversation

juancarlospaco
Copy link
Collaborator

@@ -1355,6 +1355,14 @@ proc rstToLatex*(rstSource: string; options: RstParseOptions): string {.inline,
rstGenera.renderRstToOut(rstParse(rstSource, "", 1, 1, option, options), result)


proc rstToJson*(rstSource: string; options: RstParseOptions): string {.inline, since: (1, 3).} =
## Convenience proc for `renderRstToJson` and `rstParse`.
runnableExamples: echo rstToJson("*Hello* **world**", {})
Copy link
Member

@timotheecour timotheecour Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use echo, use doAssert ..., otherwise it doesn't tell you how this works

@@ -1355,6 +1355,14 @@ proc rstToLatex*(rstSource: string; options: RstParseOptions): string {.inline,
rstGenera.renderRstToOut(rstParse(rstSource, "", 1, 1, option, options), result)


proc rstToJson*(rstSource: string; options: RstParseOptions): string {.inline, since: (1, 3).} =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • why not use the hook mechanism in jsonutils?
  • badly named since it returns string, not JsonNode; rstToJsonString would be more accurate
  • this doesn't compose; instead, the hook mechanism in jsonutils would allow composition, eg:
type RstSource = distinct string
let b = ("foo", @[RstSource"*hello*", RstSource"**world**"]).toJson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants