Giter Club home page Giter Club logo

rst2rfcxml's Introduction

rst2rfcxml

OpenSSF Scorecard

Convert reStructured Text (RST) to xml2rfc Version 3.

Note that the project name uses the term "rfcxml" to refer to xml2rfc Version 3, since the alternative "rst2xml2rfc" could imply it converts from rst to rfc, via xml, which is not the case.

Installation

rst2rfcxml can be installed either in binary form, or by building from source.

Installing in binary form

Download and unzip the latest "Ubuntu.Release.rst2rfcxml.zip" (for Linux) or "Windows.Release.rst2rfcxml.zip" (for Windows) from https://github.com/dthaler/rst2rfcxml/releases.

Building from source

Clone:

git clone --recurse-submodules https://github.com/dthaler/rst2rfcxml.git
cd rst2rfcxml

Make on Linux:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

The resulting binary will be in ./build/rst2rfcxml/rst2rfcxml.

Make on Windows (which uses a multi-configuration generator):

cmake -B build
cmake --build build --config Release

The resulting binary will be in .\build\rst2rfcxml\Release\rst2rfcxml.exe.

Usage

A reStructured Text to xml2rfc Version 3 converter
Usage: rst2rfcxml.exe [OPTIONS] input...

Positionals:
  input TEXT ... REQUIRED     Input filenames

  Options:
  -h,--help                   Print this help message and exit
  --version                   Display program version information and exit
  -o TEXT                     Output filename
  -i TEXT ... REQUIRED        Input filenames

Multiple input files are read as if they were one large file. This allows (for example) a "prologue" file to contain xml2rfc specific definitions, to be included before the main RST file.

For example, conversion from RST files to an Internet-Draft might be done as follows:

$ rst2rfcxml sample-prologue.rst sample.rst -o draft-thaler-sample-00.xml
$ xml2rfc --html draft-thaler-sample-00.xml
$ firefox draft-thaler-sample-00.html

However the include directive can be used instead by having a "skeleton" file that includes the main RST file at an appropriate point. Thus, conversion to an Internet-Draft might be done as follows:

$ rst2rfcxml sample-skeleton.rst -o draft-thaler-sample-00.xml
$ xml2rfc --html draft-thaler-sample-00.xml
$ firefox draft-thaler-sample-00.html

The following subsections provide more details on the contents of RST files.

Header directive

To generate an xml2rfc header, the header directive must be included.

.. header::

This directive must appear after any xml2rfc specific definitions discussed below.

xml2rfc specific definitions

The replace directive is used to configure xml2rfc specific definitions. The general syntax is:

.. |<name>| replace:: <value>

where <name> is a string defined below, and <value> is the value to set it to.

Common settings

  • docName: The filename of the draft without any extension.
  • ipr: The ipr value, such as trust200902.
  • category: The category, such as std.
  • titleAbbr: Abbreviated title to appear in the page header.
  • submissionType: The stream name, such as IETF.
  • baseTargetUri: Base URI for any external references whose target is a relative URI reference.
  • abstract: Text of abstract.

Example:

.. |docName| replace:: draft-thaler-sample-00
.. |ipr| replace:: trust200902
.. |category| replace:: std
.. |titleAbbr| replace:: Sample Abbreviated Title
.. |submissionType| replace:: IETF
.. |baseTargetUri| replace:: http://example.com/path

Author settings

The document must have at least one author, and can have multiple authors.

  • author[<anchor>].fullname: Full name to associate with the author with the indicated <anchor>.
  • author[<anchor>].asciiFullname: Optional. ASCII full name to associate with the author with the indicated <anchor>.
  • author[<anchor>].organization: Optional. Affiliation to associate with the author with the indicated <anchor>.
  • author[<anchor>].role: Optional. Role to associate with the author with the indicated <anchor>.
  • author[<anchor>].surname: Surname to associate with the author with the indicated <anchor>.
  • author[<anchor>].asciiSurname: Optional. ASCII surname to associate with the author with the indicated <anchor>.
  • author[<anchor>].initials: Initials to associate with the author with the indicated <anchor>.
  • author[<anchor>].asciiInitials: Optional. ASCII initials to associate with the author with the indicated <anchor>.
  • author[<anchor>].email: Optional. Email address to associate with the author with the indicated <anchor>.
  • author[<anchor>].phone: Optional. Phone number to associate with the author with the indicated <anchor>.
  • author[<anchor>].city: Optional. City to associate with the author with the indicated <anchor>.
  • author[<anchor>].code: Optional. Postal code to associate with the author with the indicated <anchor>.
  • author[<anchor>].country: Optional. Country to associate with the author with the indicated <anchor>.
  • author[<anchor>].region: Optional. State or region to associate with the author with the indicated <anchor>.
  • author[<anchor>].street: Optional. Street address to associate with the author with the indicated <anchor>.
  • author[<anchor>].postalLine: Optional, may occur multiple times. Postal address lines to use instead of using street, city, region, code, and country.

Example:

.. |author[0].fullname| replace:: John Doe
.. |author[0].organization| replace:: ACME
.. |author[0].role| replace:: editor
.. |author[0].surname| replace:: Doe
.. |author[0].initials| replace:: J.
.. |author[0].email| replace:: [email protected]
.. |author[0].phone| replace:: 555-1212
.. |author[0].city| replace:: Anytown
.. |author[0].region| replace:: WA
.. |author[0].country| replace:: USA

The <anchor> values do not appear in the XML but are merely used to group fields of the same author.

External References

RST files specify external references using the following syntax:

`Some Title <https://example.com/path#optional-fragment-id>`_

To specify the Internet-Draft format reference, one must map the URI (not including the fragment) portion as follows:

  • ref[<anchor>].target: Target URI to associate with the reference with the indicated <anchor>. If the target is a relative reference, it is relative to the baseTargetUri specified above.
  • ref[<anchor>].title: Title to associate with the reference with the indicated <anchor>.
  • ref[<anchor>].type: Must be set to normative or informative.
  • ref[<anchor>].author[<anchor>].fullname: Author fullname.
  • ref[<anchor>].author[<anchor>].initials: Author initials.
  • ref[<anchor>].author[<anchor>].surname: Author surname.
  • ref[<anchor>].seriesInfo.name: Series info name. Must be set to RFC, Internet-Draft, or DOI.
  • ref[<anchor>].seriesInfo.value: Series info value. See Section 2.47 of RFC 7991.
  • ref[<anchor>].date.day: Optional day of publication.
  • ref[<anchor>].date.month: Optional month of publication.
  • ref[<anchor>].date.year: Year of publication.

Example:

.. |ref[SAMPLE].title| replace:: Sample Title
.. |ref[SAMPLE].target| replace:: https://example.com/path
.. |ref[SAMPLE].type| replace:: normative
.. |ref[SAMPLE].author[0].fullname| replace:: John Doe
.. |ref[SAMPLE].author[0].initials| replace:: J.
.. |ref[SAMPLE].author[0].surname| replace:: Doe
.. |ref[SAMPLE].seriesInfo.name| replace:: Internet-Draft
.. |ref[SAMPLE].seriesInfo.value| replace:: draft-ietf-sample-name-00
.. |ref[SAMPLE].date.month| replace:: April
.. |ref[SAMPLE].date.year| replace:: 2024

Introduction

Any text under the title in an RST file and above any subsequent section header is considered to be part of an Introduction section that will be added.

Sample Files

rst2rfcxml's People

Contributors

dependabot[bot] avatar dthaler avatar qmonnet avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

qmonnet

rst2rfcxml's Issues

Add support for "..table"

The latest bpf instruction-set.rst has:

.. table:: Meaning of signedness notation.                                                                                                                                                                                                     

  ==== =========
  `S`  Meaning
  ==== =========
  `u`  unsigned
  `s`  signed
  ==== =========

which is not converted to XML correctly.

Make internal links show link title

RST viewer:

the start of the [Function information](https://github.com/dthaler/ebpf-docs-1/blob/elf/rst/elf.rst#function-information)

Current conversion:

the start of the [Section 5.4.1](https://github.com/dthaler/rst2rfcxml/issues/new#functioninformation)

Want:

the start of the Function information ([Section 5.4.1](https://github.com/dthaler/rst2rfcxml/issues/new#functioninformation))

or

the start of the [Function information (Section 5.4.1)](https://github.com/dthaler/rst2rfcxml/issues/new#functioninformation)

Table inside list element not handled

Error:

draft-ietf-bpf-isa.xml(2688): Error: Did not expect element table there, at /rfc/middle/section[5]/section[1]/ul/table

Source excerpt:

* Registration policy (see `RFC 8126 section 4 <https://www.rfc-editor.org/rfc/rfc8126.html#section-4>`_ for details):
+
+  * Permanent: Standards action or IESG Review
+  * Provisional: Specification required
+  * Historical: Specification required
+* Initial registrations:
+
+======  ==========================  ========  ========  ===========  ===============================================
+name    description                 includes  excludes  status       reference
+======  ==========================  ========  ========  ===========  ===============================================
+atom32  32-bit atomic instructions  -         -         Permanent    RFCXXX `Atomic operations`_
+atom64  64-bit atomic instructions  atom32    -         Permanent    RFCXXX `Atomic operations`_
+base32  32-bit base instructions    -         -         Permanent    RFCXXX
+base64  64-bit base instructions    base32    -         Permanent    RFCXXX
+div32   32-bit division and modulo  -         -         Permanent    RFCXXX `Arithmetic instructions`_
+div64   64-bit division and modulo  div32     -         Permanent    RFCXXX `Arithmetic instructions`_
+legacy  Legacy packet instructions  -         -         Historical   RFCXXX `Legacy BPF Packet access instructions`_
+======  ==========================  ========  ========  ===========  ===============================================

Add support for ".. glossary"

The bpf instruction-set.rst has:

.. glossary::

  Sign Extend
    To `sign extend an` ``X`` `-bit number, A, to a` ``Y`` `-bit number, B  ,` means to

    #. Copy all ``X`` bits from `A` to the lower ``X`` bits of `B`.
    #. Set the value of the remaining ``Y`` - ``X`` bits of `B` to the value of
       the  most-significant bit of `A`.

This is not converted correctly.

References:

ASCII art figures are not rendered correctly

RST renders correctly in github:
https://github.com/ebpffoundation/ebpf-docs/blob/update/rst/instruction-set.rst#13instruction-encoding

But XML2RFC version is not rendered correctly:
https://htmlpreview.github.io/?https://raw.githubusercontent.com/ebpffoundation/ebpf-docs/pdf/draft-thaler-bpf-isa.html#name-instruction-encoding

Original rst text:

This is depicted in the following figure::

        basic_instruction
  .-----------------------------.
  |                             |
  code:8 regs:8 offset:16 imm:32 unused:32 imm:32
                                 |              |
                                 '--------------'
                                pseudo instruction

XML:

   <t>
    This is depicted in the following figure:
   </t>
   <blockquote>    basic_instruction
    .-----------------------------.
    |                             |
    code:8 regs:8 offset:16 imm:32 unused:32 imm:32
    |              |
    '--------------'
    pseudo instruction
   </blockquote>

* inside literal block

RST:

0xc3    any  0xe1  lock::                                               `Atomic operations`_

                       temp = *(u32 *)(dst + offset)
                       *(u32 *)(dst + offset) = src
                       src = temp

is converted to

<td>temp = <em>(u32</em>)(dst + offset)</td>

instead of

<td>temp = *(u32 *)(dst + offset)</td>

Duplicate anchors in dt

findstr /n dt.anchor draft-ietf-bpf-isa.xml

218:     <dt anchor="term-sign-extend">
323:     <dt anchor="term---opcode--">
342:     <dt anchor="term---regs--">
369:     <dt anchor="term---offset--">
377:     <dt anchor="term---imm--">
428:     <dt anchor="term---opcode--">
436:     <dt anchor="term---regs--">
444:     <dt anchor="term---offset--">
452:     <dt anchor="term---imm--">
460:     <dt anchor="term---reserved--">
468:     <dt anchor="term---next_imm--">
683:    <dt anchor="term---code--">
691:    <dt anchor="term---s--source---">
746:    <dt anchor="term---instruction-class--">
1906:    <dt anchor="term---mode--">
2060:    <dt anchor="term---sz--size---">
2152:    <dt anchor="term---class--">

Errors at https://author-tools.ietf.org/:

xml2rfc error: (441) Invalid attribute anchor for element dt, at /rfc/middle/section[2]/section[2]/dl/dt[1]
(449) Invalid attribute anchor for element dt, at /rfc/middle/section[2]/section[2]/dl/dt[2]
(457) Invalid attribute anchor for element dt, at /rfc/middle/section[2]/section[2]/dl/dt[3]
(465) Invalid attribute anchor for element dt, at /rfc/middle/section[2]/section[2]/dl/dt[4]
(20) Invalid document before running preptool.

The line numbers are off by 3, but that's not the problem here, the problems is that the anchors in those lines were previously defined.

Create initial release

Create release binaries that can be used by other github projects
Upload build artifacts that can easily be used as such

Generate an arm64 binary release for Ubuntu

I get the following error with Ubuntu jammy (arm64, building under macOS docker):
I'm using the source from https://github.com/dthaler/rst2rfcxml/archive/refs/tags/v<version>.tar.gz.

0.682 -- The C compiler identification is GNU 11.4.0
0.727 -- The CXX compiler identification is GNU 11.4.0
0.734 -- Detecting C compiler ABI info
0.782 -- Detecting C compiler ABI info - done
0.787 -- Check for working C compiler: /usr/bin/cc - skipped
0.787 -- Detecting C compile features
0.787 -- Detecting C compile features - done
0.789 -- Detecting CXX compiler ABI info
0.842 -- Detecting CXX compiler ABI info - done
0.847 -- Check for working CXX compiler: /usr/bin/c++ - skipped
0.847 -- Detecting CXX compile features
0.848 -- Detecting CXX compile features - done
0.848 CMake Error at CMakeLists.txt:9 (add_subdirectory):
0.848   The source directory
0.848
0.848     /root/rst2rfcxml-0.8/external/fmt
0.848
0.848   does not contain a CMakeLists.txt file.
0.848
0.848
0.849 -- Configuring incomplete, errors occurred!
0.849 See also "/root/rst2rfcxml-0.8/build/CMakeFiles/CMakeOutput.log".

Add test cases

  1. Move business logic into a static lib.
  2. Create a catch2 based test binary.
  3. Add various test cases.
  4. Invoke test in CI/CD.

Add support for :term:

Used by bpf instruction-set.rst

In xml2rfc v3, <dt> can have an anchor attribute which can be referenced in an <xref>

Add support for emphasis

*foo* should be converted to <em>foo</em> without breaking existing support for **foo** bolding or \* literals

External references

RST:

`eBPF programs <instruction-set.rst#instruction-encoding>`_

means "eBPF programs" is a title, "instruction-set.rst" is the document referenced, and "instruction-encoding" is the section within that document.

Error hit by ebpf-docs repo

https://github.com/ietf-wg-bpf/ebpf-docs/actions/runs/6784438622/job/18440736964 :

Traceback (most recent call last):
  File "/home/runner/.local/bin/xml2rfc", line 8, in <module>
    sys.exit(main())
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/run.py", line 746, in main
    writer.write(filename)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 279, in write
    html_tree = self.html_tree()
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 257, in html_tree
    html_tree = self.render(None, self.root)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 677, in render_rfc
    self.render(body, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 348, in skip_renderer
    self.render(h, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 2398, in render_section
    self.render(section, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 2677, in render_ul
    self.render(ul, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 1800, in render_li
    li = self.render_li_ul(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 1794, in render_li_ul
    self.render(li, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 2528, in render_t
    self.render(p, c)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 334, in render
    res = func(h, x)
  File "/home/runner/.local/lib/python3.8/site-packages/xml2rfc/writers/html.py", line 2[88](https://github.com/ietf-wg-bpf/ebpf-docs/pull/62/checks#step:7:89)8, in render_xref
    label = 'Section' if section[0].isdigit() else 'Appendix' if re.search(r'^[A-Z](\.|$)', section) else 'Part'
IndexError: string index out of range

Add support for multi-line entries in an unordered list

* One
* Two with a continuation
  of the same line.

Is incorrectly converted to

  <ul>
   <li>
    One
    <dl>
     <dt>
      <ul>
       <li>
        Two with a continuation
        of the same line.
       </li>
      </ul>
     </dt>
    </dl>
   </li>
  </ul>

It should instead be:

  <ul>
   <li>
    One
   </li>
   <li>
    Two with a continuation
    of the same line.
   </li>
  </ul>

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.