Skip to content

Commit

Permalink
Refactor code style, add links to js versions
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 7, 2024
1 parent 567e7e0 commit e7ed526
Show file tree
Hide file tree
Showing 69 changed files with 894 additions and 876 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
name: main
on:
- pull_request
- push
jobs:
main:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check && cargo clippy --examples --tests --benches --all-features
- run: cargo test --all-features
- run: cargo clippy -p mdast_util_to_markdown
- run: cargo test -p mdast_util_to_markdown
coverage:
- run: cargo install cargo-tarpaulin
- run: cargo tarpaulin --features json --out xml
- uses: codecov/codecov-action@v4
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
components: clippy, rustfmt
toolchain: stable
- run: cargo install cargo-tarpaulin && cargo tarpaulin --features json --out xml
- uses: codecov/codecov-action@v4
- run: cargo fmt --check && cargo clippy --all-features --all-targets --workspace
- run: cargo test --all-features --workspace
name: main
on:
- pull_request
- push
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.log
*.lock
coverage/
target
target/
commonmark-data.txt
unicode-data.txt
fuzz/target
Expand Down
66 changes: 33 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
[package]
name = "markdown"
version = "1.0.0-alpha.21"
authors = ["Titus Wormer <[email protected]>"]
edition = "2018"
rust-version = "1.56"
description = "CommonMark compliant markdown parser in Rust with ASTs and extensions"
homepage = "https://github.com/wooorm/markdown-rs"
repository = "https://github.com/wooorm/markdown-rs"
license = "MIT"
keywords = ["commonmark", "markdown", "parse", "render", "tokenize"]
categories = ["compilers", "encoding", "parser-implementations", "parsing", "text-processing"]
include = ["src/", "license"]

[workspace]
members = ["generate", "mdast_util_to_markdown"]

[workspace.dependencies]
pretty_assertions = "1"

[[bench]]
harness = false
name = "bench"
path = "benches/bench.rs"
harness = false

[features]
default = []
json = ["serde"]
serde = ["dep:serde"]
log = ["dep:log"]

[dependencies]
log = { version = "0.4", optional = true }
unicode-id = { version = "0.3", features = ["no_std"] }
serde = { version = "1", features = ["derive"], optional = true }
log = { optional = true, version = "0.4" }
serde = { features = ["derive"], optional = true, version = "1" }
unicode-id = { features = ["no_std"], version = "0.3" }

[dev-dependencies]
env_logger = "0.11"
criterion = "0.5"
env_logger = "0.11"
pretty_assertions = { workspace = true }
serde_json = { version = "1" }
swc_core = { version = "0.100", features = [
"common",
"ecma_ast",
"ecma_visit",
"ecma_parser",
"common",
"ecma_visit",
] }

[features]
default = []
json = ["serde"]
log = ["dep:log"]
serde = ["dep:serde"]

[package]
authors = ["Titus Wormer <[email protected]>"]
categories = ["compilers", "encoding", "parser-implementations", "parsing", "text-processing"]
description = "CommonMark compliant markdown parser in Rust with ASTs and extensions"
edition = "2018"
homepage = "https://github.com/wooorm/markdown-rs"
include = ["src/", "license"]
keywords = ["commonmark", "markdown", "parse", "render", "tokenize"]
license = "MIT"
name = "markdown"
repository = "https://github.com/wooorm/markdown-rs"
rust-version = "1.56"
version = "1.0.0-alpha.21"

[workspace]
members = ["generate", "mdast_util_to_markdown"]

[workspace.dependencies]
pretty_assertions = "1"
14 changes: 7 additions & 7 deletions generate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[dependencies]
regex = "1"
reqwest = "0.12"
tokio = { features = ["full"], version = "1" }

[package]
name = "markdown-generate"
version = "0.0.0"
authors = ["Titus Wormer <[email protected]>"]
edition = "2018"
name = "markdown-generate"
publish = false

[dependencies]
regex = "1"
reqwest = "0.12"
tokio = { version = "1", features = ["full"] }
version = "0.0.0"
12 changes: 6 additions & 6 deletions mdast_util_to_markdown/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "mdast_util_to_markdown"
version = "0.0.0"
edition = "2018"
license = "MIT"

[dependencies]
markdown = { path = "../" }
regex = { version = "1" }

[dev-dependencies]
pretty_assertions = { workspace = true }

[package]
edition = "2018"
license = "MIT"
name = "mdast_util_to_markdown"
version = "0.0.0"
4 changes: 4 additions & 0 deletions mdast_util_to_markdown/src/association.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Traits for <https://github.com/syntax-tree/mdast#association>.
//!
//! JS equivalent: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/70e1a4f/types/mdast/index.d.ts#L48.

use alloc::string::String;
use markdown::mdast::{Definition, ImageReference, LinkReference};

Expand Down
110 changes: 65 additions & 45 deletions mdast_util_to_markdown/src/configure.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,96 @@
//! Configuration.
//!
//! JS equivalent: https://github.com/syntax-tree/mdast-util-to-markdown/blob/fd6a508/lib/types.js#L307.

#[derive(Clone, Copy)]
/// Configuration for indent of lists.
pub enum IndentOptions {
/// Depends on the item and its parent list: uses `IndentOptions::One` if
/// the item and list are tight and `IndentOptions::Tab` otherwise.
Mixed,
/// The size of the bullet plus one space.
One,
/// Tab stop.
Tab,
}

/// Configuration.
pub struct Options {
/// Marker to use for bullets of items in unordered lists ('*', '+', or '-', default: '*').
/// Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or
/// `'-'`, default: `'*'`).
pub bullet: char,
// Marker to use in certain cases where the primary bullet doesn’t work
// ('*', '+', or '-', default: '-' when bullet is '*', '*' otherwise).
pub bullet_other: char,
/// Marker to use for bullets of items in ordered lists ('.' or ')', default: '.').
/// Marker to use for bullets of items in ordered lists (`'.'` or `')'`,
/// default: `'.'`).
pub bullet_ordered: char,
/// Marker to use for emphasis ('*' or '_', default: '*').
/// Marker to use in certain cases where the primary bullet doesn’t work
/// (`'*'`, `'+'`, or `'-'`, default: `'-'` when bullet is `'*'`, `'*'`
/// otherwise).
pub bullet_other: char,
/// Whether to add the same number of number signs (`#`) at the end of an
/// ATX heading as the opening sequence (`bool`, default: `false`).
pub close_atx: bool,
/// Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`).
pub emphasis: char,
// Marker to use for fenced code ('`' or '~', default: '`').
/// Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``).
pub fence: char,
/// Whether to use fenced code always (bool, default: true). The default is to use fenced code
/// if there is a language defined, if the code is empty, or if it starts or ends in blank lines.
/// Whether to use fenced code always (`bool`, default: `true`).
/// The default is to use fenced code if there is a language defined,
/// if the code is empty,
/// or if it starts or ends in blank lines.
pub fences: bool,
// How to indent the content of list items (default: 'IndentOptions::One').
/// Whether to increment the counter of ordered lists items (`bool`,
/// default: `true`).
pub increment_list_marker: bool,
/// How to indent the content of list items (default: `IndentOptions::One`).
pub list_item_indent: IndentOptions,
/// Marker to use for titles ('"' or "'", default: '"').
/// Marker to use for titles (`'"'` or `"'"`, default: `'"'`).
pub quote: char,
/// Marker to use for thematic breaks ('*', '-', or '_', default: '*').
pub rule: char,
// Marker to use for strong ('*' or '_', default: '*').
pub strong: char,
// Whether to increment the counter of ordered lists items (bool, default: true).
pub increment_list_marker: bool,
/// Whether to add the same number of number signs (#) at the end of an ATX heading as the
/// opening sequence (bool, default: false).
pub close_atx: bool,
/// Whether to always use resource links (bool, default: false). The default is to use autolinks
/// (<https://example.com>) when possible and resource links ([text](url)) otherwise.
/// Whether to always use resource links (`bool`, default: `false`).
/// The default is to use autolinks (`<https://example.com>`) when possible
/// and resource links (`[text](url)`) otherwise.
pub resource_link: bool,
/// Whether to add spaces between markers in thematic breaks (bool, default: false).
/// Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default:
/// `'*'`).
pub rule: char,
/// Number of markers to use for thematic breaks (`u32`, default: `3`, min:
/// `3`).
pub rule_repetition: u32,
/// Whether to add spaces between markers in thematic breaks (`bool`,
/// default: `false`).
pub rule_spaces: bool,
/// Whether to use setext headings when possible (bool, default: false). The default is to always
/// use ATX headings (# heading) instead of setext headings (heading\n=======). Setext headings
/// cannot be used for empty headings or headings with a rank of three or more.
/// Whether to use setext headings when possible (`bool`, default:
/// `false`).
/// The default is to always use ATX headings (`# heading`) instead of
/// setext headings (`heading\n=======`).
/// Setext headings cannot be used for empty headings or headings with a
/// rank of three or more.
pub setext: bool,
/// Whether to join definitions without a blank line (bool, default: false).
/// Marker to use for strong (`'*'` or `'_'`, default: `'*'`).
pub strong: char,
/// Whether to join definitions without a blank line (`bool`, default:
/// `false`).
pub tight_definitions: bool,
// Number of markers to use for thematic breaks (u32, default: 3, min: 3).
pub rule_repetition: u32,
}

#[derive(Copy, Clone)]
pub enum IndentOptions {
// Depends on the item and its parent list uses 'One' if the item and list are tight and 'Tab'
// otherwise.
Mixed,
// The size of the bullet plus one space.
One,
/// Tab stop.
Tab,
}

impl Default for Options {
fn default() -> Self {
Self {
bullet: '*',
bullet_other: '-',
bullet_ordered: '.',
bullet_other: '-',
close_atx: false,
emphasis: '*',
fence: '`',
fences: true,
increment_list_marker: true,
rule_repetition: 3,
list_item_indent: IndentOptions::One,
quote: '"',
resource_link: false,
rule: '*',
strong: '*',
close_atx: false,
rule_repetition: 3,
rule_spaces: false,
resource_link: false,
setext: false,
strong: '*',
tight_definitions: false,
}
}
Expand Down
Loading

0 comments on commit e7ed526

Please sign in to comment.