Coder Social home page Coder Social logo

demizer / go-rst Goto Github PK

View Code? Open in Web Editor NEW
51.0 51.0 3.0 6.37 MB

Parse reStructuredText with Go.

License: MIT License

Go 100.00%
cli cli-utilities go parser parser-library restructuredtext restructuredtext-parser transpiler web-application

go-rst's People

Contributors

demizer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-rst's Issues

reStructuredText tables make me sad :(

There is no way to to align text within the cells.

Consider creating a custom directive that uses GFM markdown table format or the table format from Textile.

Fix node count on critical error for mismatched nodes

In the checkParseNodes() function in parse_test.go there is a check that compares the number of parsed nodes to expected nodes from the json test data and produces a critical error if the counts do not match.

Using len(eTree) does not include nested nodes in NodeLists.

Provide tests for lexer function

The lexer functions need to be properly tested, similar to how the parser functions are tested.

peek()
peekBack()
next()
backup()

While implementing inline markup, I found a few problems with next() and backup() that should have been found with proper testing!

Full Update of ALL Documentation

Follows #9 and #10

Documentation would only be developer documentation for integrating go-rst with other go projects. The upstream docutils documents restructuredtext adequately.

Lexer tests should run first

I just ran into an error where the lexer tests failed but the parser tests still ran and resulted in a panic.

Remove modified date from README.

Does the date mean the project was modified on that date?... It would probably seem confusing to someone not familiar with the setup so it should be removed. That's what Git is for!

Rewrite the README

It should have badge bling and a screenshot. Everyone loves screen shots. See go-elog project for inspiration.

Write a blog post about testing in go-rst

Requies #10

The blog post should cover:

  1. Converting docutils tests to json
    1. Problems with docutils tests
      • psuedo xml not easily portable
    2. testdata
      1. portable rst tests are easier to use.
        • Lex items are easy to setup with separate rst file.
        • UltiSnips for fast *-items.json and *-node.json file creation.
      2. comparing json objects is painful, but not too bad. Highlight recursive compare code.
  2. Test infrastructure
    1. testdata directory structure
      • Good and Bad tests
    2. Debug output
    3. go debugger? delve?
    4. calling test data
      • test.go files and adding a new test.

      • running a single test

      • debugging a test problem
        Remove lines 442-451 in parse_test.go to produce a panic.
        Readd the lines and show the following error:

        [demizer@lithium]$ gtr TestParseCommentNoBlankLineBad0000
        === RUN TestParseCommentNoBlankLineBad0000
        
        
        Sat Dec 06 13:31:06 PST 2014 :: [CRITICAL] 3 Parse Nodes
        
        ([]parse.Node) (len=3 cap=4) {
          (*parse.CommentNode)(0xc2080b5980)({
              ID: (parse.ID) 1,
              Type: (parse.NodeType) 8,
              Text: (string) (len=9) "A comment",
              Length: (int) 9,
              StartPosition: (parse.StartPosition) 4,
              Line: (parse.Line) 1
          }),
          (*parse.ParagraphNode)(0xc2080b5bc0)({
              ID: (parse.ID) 2,
              Type: (parse.NodeType) 1,
              Text: (string) (len=13) "no blank line",
              Length: (int) 13,
              Line: (parse.Line) 2,
              StartPosition: (parse.StartPosition) 1
          }),
          (*parse.ParagraphNode)(0xc2080b5e00)({
              ID: (parse.ID) 3,
              Type: (parse.NodeType) 1,
              Text: (string) (len=12) "A paragraph.",
              Length: (int) 12,
              Line: (parse.Line) 4,
              StartPosition: (parse.StartPosition) 1
          })
        }
        
        
        Sat Dec 06 13:31:06 PST 2014 :: [CRITICAL] 4 Expected Nodes
        
        ([]interface {}) (len=4 cap=4) {
          (map[string]interface {}) (len=6) {
              (string) (len=13) "startPosition": (float64) 4,
              (string) (len=4) "line": (float64) 1,
              (string) (len=6) "length": (float64) 9,
              (string) (len=2) "id": (float64) 1,
              (string) (len=4) "type": (string) (len=11) "NodeComment",
              (string) (len=4) "text": (string) (len=9) "A comment"
          },
          (map[string]interface {}) (len=5) {
              (string) (len=4) "type": (string) (len=17) "NodeSystemMessage",
              (string) (len=8) "severity": (string) (len=7) "WARNING",
              (string) (len=4) "line": (float64) 2,
              (string) (len=8) "nodeList": ([]interface {}) (len=1 cap=1) {
                  (map[string]interface {}) (len=4) {
                      (string) (len=2) "id": (float64) 3,
                      (string) (len=4) "type": (string) (len=13) "NodeParagraph",
                      (string) (len=4) "text": (string) (len=63) "Explicit markup ends without a blank line; unexpected unindent.",
                      (string) (len=6) "length": (float64) 63
                  }
              },
              (string) (len=2) "id": (float64) 2
          },
          (map[string]interface {}) (len=6) {
              (string) (len=6) "length": (float64) 13,
              (string) (len=2) "id": (float64) 4,
              (string) (len=4) "type": (string) (len=13) "NodeParagraph",
              (string) (len=4) "text": (string) (len=13) "no blank line",
              (string) (len=13) "startPosition": (float64) 1,
              (string) (len=4) "line": (float64) 2
          },
          (map[string]interface {}) (len=6) {
              (string) (len=4) "text": (string) (len=11) "A paragraph",
              (string) (len=13) "startPosition": (float64) 1,
              (string) (len=4) "line": (float64) 4,
              (string) (len=6) "length": (float64) 11,
              (string) (len=2) "id": (float64) 5,
              (string) (len=4) "type": (string) (len=13) "NodeParagraph"
          }
        }
        
        
        Sat Dec 06 13:31:06 PST 2014 :: [CRITICAL] The number of parsed nodes does not match expected nodes!
        exit status 1
        FAIL  github.com/demizer/go-rst/parse 0.005s
        

Project website

go-rst needs a proper project website.

The site will be built using Hugo, in markdown initially, but hopefully in the future with go-rst.

The http://restructuredtext.com domain has been acquired for this purpose. The project page should host an online editor and restructuredtext validator using Python, Nim, and Go. See rst.ninjs.org for inspiration.

  • Use CloudFlare
  • Compile go-rst to Javascript using GopherJS
    • WYSIWYG editor
    • View lex items
    • View parse nodes
  • Use hyde for static generation
  • Public API
    • Parse to HTML
    • Parse to JSON
  • Blog
  • Links to docutils spec and various sites.

The project page should also contain a link to the docutils project page and the spec.

DRY: Lexing a token of the current line

Many of the lexing function contain this block:

TestLexCommentInDefinitionGood0400
    for {
        l.next()
        if l.isEndOfLine() && l.mark == utf8.RuneError {
            l.emit(itemTerm)
            break
        }
    }

This should be reduced down to a function: emitCurrentLine(t token) or something.

Document test functions

parse_test.go is magical and does comparisons of JSON objects to Go objects, but is barely documented. After not looking at it for four months some of it is kind of fuzzy.

Refactor test collection method

Currently, tests are called with hard-coded paths:

    testPath := "test_section/02-title-bad/" +
        "02.02_short_title_short_overline_missing_underline"

Ideally, it should be possible to call a test by the actual file name of the test instead of having using a "testPath" variable.

So for example:

func TestShortTitleWithShortOverlineMissingUnderline0202(t *testing.Test) {
        run_test("short_title_short_overline_missing_underline")
}

Lex/Parse Directives

  • Code Blocks
    • Lex
    • Parse
    • For syntax highlighting, use Go based language parser and fallback to pygments.
  • Image Blocks
    • Lex
    • Parse
  • Admonitions
    • Lex Generic Admonition
    • Parse Generic Admonition
    • Lex Attention
    • Parse Attention
    • Lex Caution
    • Parse Caution
    • Lex Danger
    • Parse Danger
    • Lex Error
    • Parse Error
    • Lex Hint
    • Parse Hint
    • Lex Important
    • Parse Important
    • Lex Note
    • Parse Note
    • Lex Tip
    • Parse Tip
    • Lex Warning
    • Parse Warning

Remove extraneous debug output

The debug output "START" and "END" for every function is useful while debugging, but is it necessary?
Explore other methods for studying the execution path of the library.

Allow arbitrary insertion into the token ring buffer

An API for Item insertion into the token ring buffer. This will help clean up systemMessage().

When parsing an itemBlockQuote, the text of the item needs to be added onto the token ring manually so that the next go around in the parser will add the text as a paragraph to the NodeList of the blockquote. systemMessage() does this manually and the code doesn't read well.

Is it functioning?

Hi there,

Just want to ask is it functioning cause I have needs for rst parser in Go

Thanks,
Joe

Implement Transform API

Look to docutils for inspiration on the API that should be used to interface with the package.

Once all of the basic section tests are passing, we should implement the full API for transforming a reStructuredText document into a valid HTML webpage, or JSON output, with a working example.

  • Pluggable internal API for easily adding new transformers
  • Transform to Json
  • Transform to HTML

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.