Skip to content

Initial iteration of a codec for Org Mode#1485

Open
nokome wants to merge 1 commit intomainfrom
org-mode
Open

Initial iteration of a codec for Org Mode#1485
nokome wants to merge 1 commit intomainfrom
org-mode

Conversation

@nokome
Copy link
Copy Markdown
Member

@nokome nokome commented Jul 28, 2022

This add support for converting documents to/from htps://orgmode.org. As code comments point out it is still preliminary. Support for executable nodes such as Parameter, CodeChunk and CodeExpression is not yet enabled. This needs some research into how org-babel before continuing.

Addresses #1484 and #1483. Specifically for the latter on this branch one can convert .org file to JSON

> cargo run --bin stencila -- convert fixtures/articles/simple.org - --to json
    Finished dev [unoptimized + debuginfo] target(s) in 0.29s
     Running `target/debug/stencila convert fixtures/articles/simple.org - --to json`
{
  "type": "Article",
  "authors": [
    {
      "type": "Person",
      "familyNames": [
        "Bentley"
      ],
      "givenNames": [
        "Nokome"
      ]
    }
  ],
  "content": [
    {
      "type": "Heading",
      "content": [
        "Introduction"
      ],
      "depth": 1
    },
    {
      "type": "Paragraph",
      "content": [
        "A simple Org Mode article for testing. When making changes please note that test snapshots based on this fixture may need to be updated."
      ]
    },
    {
      "type": "Heading",
      "content": [
        "Methods"
      ],
      "depth": 1
    },
    {
      "type": "Paragraph",
      "content": [
        "This is the methods section."
      ]
    },
    {
      "type": "Heading",
      "content": [
        "Results"
      ],
      "depth": 1
    },
    {
      "type": "Paragraph",
      "content": [
        "The results include a table (Table 1)."
      ]
    },
    {
      "type": "Table",
      "rows": [
        {
          "type": "TableRow",
          "cells": [
            {
              "type": "TableCell",
              "cellType": "Header",
              "content": [
                "Group"
              ]
            },
            {
              "type": "TableCell",
              "cellType": "Header",
              "content": [
                "Value"
              ]
            }
          ],
          "rowType": "Header"
        },
        {
          "type": "TableRow",
          "cells": [
            {
              "type": "TableCell",
              "content": [
                "A"
              ]
            },
            {
              "type": "TableCell",
              "content": [
                "1.1"
              ]
            }
          ]
        },
        {
          "type": "TableRow",
          "cells": [
            {
              "type": "TableCell",
              "content": [
                "B"
              ]
            },
            {
              "type": "TableCell",
              "content": [
                "2.2"
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "Heading",
      "content": [
        "Discussion"
      ],
      "depth": 1
    },
    {
      "type": "Paragraph",
      "content": [
        "This is the discussion section."
      ]
    }
  ],
  "title": [
    "A simple Org Mode article for testing"
  ]
}

and HTML with Microdata,

cargo run --bin stencila -- convert fixtures/articles/simple.org - --to html
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/stencila convert fixtures/articles/simple.org - --to html`
<article data-root itemtype="https://schema.org/Article" itemscope>
  <stencila-document-toolbar></stencila-document-toolbar>
  <h1 itemprop="headline">
    <span>A simple Org Mode article for testing</span>
  </h1>
  <ol data-prop="authors">
    <li itemprop="author" itemtype="https://schema.org/Person" itemscope>
      <meta itemprop="name" content="Nokome Bentley" /><span
        data-prop="givenNames"
        ><span itemprop="givenName">Nokome</span></span
      ><span data-prop="familyNames"
        ><span itemprop="familyName">Bentley</span></span
      >
    </li>
  </ol>
  <div data-prop="content">
    <h2 itemtype="https://schema.stenci.la/Heading" itemscope>
      <span>Introduction</span>
    </h2>
    <p itemtype="https://schema.stenci.la/Paragraph" itemscope>
      <span
        >A simple Org Mode article for testing. When making changes please note
        that test snapshots based on this fixture may need to be updated.</span
      >
    </p>
    <h2 itemtype="https://schema.stenci.la/Heading" itemscope>
      <span>Methods</span>
    </h2>
    <p itemtype="https://schema.stenci.la/Paragraph" itemscope>
      <span>This is the methods section.</span>
    </p>
    <h2 itemtype="https://schema.stenci.la/Heading" itemscope>
      <span>Results</span>
    </h2>
    <p itemtype="https://schema.stenci.la/Paragraph" itemscope>
      <span>The results include a table (Table 1).</span>
    </p>
    <table itemtype="https://schema.org/Table" itemscope>
      <caption>
        <span data-prop="label"></span>
        <div data-prop="caption"></div>
      </caption>
      <tbody data-prop="rows">
        <tr itemtype="https://schema.stenci.la/TableRow" itemscope>
          <th itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>Group</span>
          </th>
          <th itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>Value</span>
          </th>
        </tr>
        <tr itemtype="https://schema.stenci.la/TableRow" itemscope>
          <td itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>A</span>
          </td>
          <td itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>1.1</span>
          </td>
        </tr>
        <tr itemtype="https://schema.stenci.la/TableRow" itemscope>
          <td itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>B</span>
          </td>
          <td itemtype="https://schema.stenci.la/TableCell" itemscope>
            <span>2.2</span>
          </td>
        </tr>
      </tbody>
    </table>
    <h2 itemtype="https://schema.stenci.la/Heading" itemscope>
      <span>Discussion</span>
    </h2>
    <p itemtype="https://schema.stenci.la/Paragraph" itemscope>
      <span>This is the discussion section.</span>
    </p>
  </div>
</article>

@nokome nokome added state: inactive Had little or no recent activity type: feature Proposes a new feature labels Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: inactive Had little or no recent activity type: feature Proposes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant