Skip to content

Commit

Permalink
Upgrades to pandoc-types 1.22 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jul 7, 2021
1 parent f8a15fb commit 4539299
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 38 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
on: [push, pull_request]

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy

- name: Setup pandoc
uses: r-lib/actions/setup-pandoc@v1
with:
pandoc-version: 2.14.0.3

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test

- name: Run cargo build
uses: actions-rs/cargo@v1
with:
command: build

- name: Run examples
uses: actions-rs/cargo@v1
with:
command: run
args: --example definition
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ readme = "README.md"
include = ["Cargo.toml", "src/**/*.rs", "tests/**/*.rs", "tests/**/*.txt", "examples/**/*.rs", "README.md", "LICENSE.txt"]
edition = "2018"

[badges]
travis-ci = { repository = "elliottslaughter/rust-pandoc-types" }

[dependencies]
serde = {version = "1.0", features=["derive"]}
serde_json = "1.0"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rust port of pandoc-types [![Build Status](https://travis-ci.org/elliottslaughter/rust-pandoc-types.svg?branch=master)](https://travis-ci.org/elliottslaughter/rust-pandoc-types)
# Rust port of pandoc-types ![Build status](https://github.com/elliottslaughter/rust-pandoc-types/actions/workflows/test.yml/badge.svg)

This library provides a Rust port of the [pandoc-types Haskell
package](https://hackage.haskell.org/package/pandoc-types).
Expand Down Expand Up @@ -29,7 +29,7 @@ itself. If that's what you're looking for, consider the
## Compatibility

The current version is **compatible with Haskell pandoc-types
1.20**. This is the most recent version at the time of writing.
1.22**. This is the most recent version at the time of writing.

## Supported modules

Expand Down
49 changes: 38 additions & 11 deletions src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use serde::ser::SerializeStruct;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

const PANDOC_API_VERSION: &'static [i32] = &[1, 20];
const PANDOC_API_VERSION: [i32; 2] = [1, 22];

#[derive(Debug, Clone, PartialEq)]
pub struct Pandoc(pub Meta, pub Vec<Block>);
Expand All @@ -14,7 +14,7 @@ impl Serialize for Pandoc {
S: Serializer,
{
let mut value = serializer.serialize_struct("Pandoc", 3)?;
value.serialize_field("pandoc-api-version", PANDOC_API_VERSION)?;
value.serialize_field("pandoc-api-version", &PANDOC_API_VERSION)?;
value.serialize_field("meta", &self.0)?;
value.serialize_field("blocks", &self.1)?;
value.end()
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Meta {
self.0.is_empty()
}

pub fn lookup(&self, key: &String) -> Option<&MetaValue> {
pub fn lookup(&self, key: &str) -> Option<&MetaValue> {
self.0.get(key)
}
}
Expand Down Expand Up @@ -87,11 +87,12 @@ pub enum Block {
Header(i32, Attr, Vec<Inline>),
HorizontalRule,
Table(
Vec<Inline>,
Vec<Alignment>,
Vec<f64>,
Vec<TableCell>,
Vec<Vec<TableCell>>,
Attr,
Caption,
Vec<ColSpec>,
TableHead,
Vec<TableBody>,
TableFoot,
),
Div(Attr, Vec<Block>),
Null,
Expand All @@ -102,6 +103,7 @@ pub enum Block {
pub enum Inline {
Str(String),
Emph(Vec<Inline>),
Underline(Vec<Inline>),
Strong(Vec<Inline>),
Strikeout(Vec<Inline>),
Superscript(Vec<Inline>),
Expand Down Expand Up @@ -130,6 +132,34 @@ pub enum Alignment {
AlignDefault,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "t", content = "c")]
pub enum ColWidth {
ColWidth(f64),
ColWidthDefault,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ColSpec(pub Alignment, pub ColWidth);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Row(pub Attr, pub Vec<Cell>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TableHead(pub Attr, pub Vec<Row>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TableBody(pub Attr, pub i32, pub Vec<Row>, pub Vec<Row>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TableFoot(pub Attr, pub Vec<Row>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Caption(pub Option<Vec<Inline>>, pub Vec<Block>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Cell(pub Attr, pub Alignment, pub i32, pub i32, pub Vec<Block>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ListAttributes(pub i32, pub ListNumberStyle, pub ListNumberDelim);

Expand Down Expand Up @@ -166,9 +196,6 @@ impl Attr {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TableCell(pub Vec<Block>);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "t", content = "c")]
pub enum QuoteType {
Expand Down
1 change: 1 addition & 0 deletions tests/pandoc_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ fn inline() {
r#"
str
*emph*
<u>underline</u>
**strong**
~~strikeout~~
^superscript^
Expand Down
25 changes: 25 additions & 0 deletions tests/tables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ Multiline table without column headers:
Second row 5.0 Here's another one. Note
the blank line between rows.
---------- --------- ----------- ---------------------------

Table with column widths:

<table>
<colgroup>
<col width="11%">
<col width="22%">
</colgroup>
<thead>
<tr>
<th>First</th>
<th>Second</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
</tbody>
</table>

0 comments on commit 4539299

Please sign in to comment.