Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize mdast to markdown #127

Merged
merged 74 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
973f760
init mdast to markdown
bnchi Aug 24, 2024
691bb87
Handle texts in a simple way
bnchi Aug 24, 2024
b2a2ed3
Add container phrasing
bnchi Aug 27, 2024
25ee1b6
Fix minor typo
bnchi Aug 27, 2024
4ff2d02
Change comment
bnchi Aug 27, 2024
06e89f5
Update comment
bnchi Aug 27, 2024
78e6529
Add support for flow containers and default joins
bnchi Aug 28, 2024
9e5e9be
Add parents macro
bnchi Aug 28, 2024
21486d1
rename join default
bnchi Aug 28, 2024
66885de
Add unsafe
bnchi Aug 29, 2024
0733560
Fix typo
bnchi Aug 29, 2024
41d01f1
Make it safe
bnchi Aug 30, 2024
dd44b06
Fix clippy issues
bnchi Aug 31, 2024
dae7d26
Reduce some of the allocations
bnchi Sep 1, 2024
b598a26
Make things less pub for now
bnchi Sep 1, 2024
e9991fd
Move mdast to md into a workspace
bnchi Sep 3, 2024
558b316
A few refactors for parent nodes abstraction
bnchi Sep 3, 2024
973de93
Refactor
bnchi Sep 3, 2024
98243d3
Add support with tests for strong, paragraph and text
bnchi Sep 4, 2024
8e2055a
Add support for emphasis
bnchi Sep 4, 2024
0d939d1
Fix minor bug
bnchi Sep 5, 2024
3072d02
Add support for heading and break
bnchi Sep 5, 2024
464f327
Refactor compile pattern
bnchi Sep 5, 2024
e94d898
More refactor for compile pattern
bnchi Sep 5, 2024
3d1a896
Make inde_stack usize
bnchi Sep 5, 2024
16a3cb0
Add support for html
bnchi Sep 5, 2024
b9752b7
Fix minor bug in html
bnchi Sep 5, 2024
a8a2351
Add valid expected unwraps
bnchi Sep 6, 2024
c1e3758
Fix typos
bnchi Sep 6, 2024
4bf37ce
Add support for thematic break
bnchi Sep 6, 2024
67aa7ee
Add support for code
bnchi Sep 7, 2024
b542777
Add support for blockquote without full tests support
bnchi Sep 7, 2024
4969d1a
Add support for list and list item
bnchi Sep 9, 2024
04fb9e0
Add support for image
bnchi Sep 12, 2024
7ff2abb
Add support for link
bnchi Sep 14, 2024
3fa6bd2
Depend on Regex less in some trivial code
bnchi Sep 14, 2024
66f5024
Few updates
bnchi Sep 14, 2024
9b03c74
Add support for inline code
bnchi Sep 14, 2024
c43f209
Add support for root
bnchi Sep 15, 2024
f3efe18
Update break comment
bnchi Sep 15, 2024
8d34b35
Add support for definition
bnchi Sep 17, 2024
e062d85
make markdown utils pub
bnchi Sep 17, 2024
2b22136
Change util visibility and make decode_named and decode_numeric pub
bnchi Sep 17, 2024
ff30eb1
Refactor association
bnchi Sep 17, 2024
9c5e808
Update the name of the association mod
bnchi Sep 17, 2024
58ff3b8
Add support for image reference
bnchi Sep 17, 2024
f512a4c
merge
bnchi Sep 17, 2024
250a6cd
Update blockquote
bnchi Sep 17, 2024
04bdc71
Add support for link reference
bnchi Sep 18, 2024
7596d29
Fix typo
bnchi Sep 19, 2024
3eef67f
Refactor
bnchi Sep 20, 2024
ddde5b4
Add support for tight defs and few refactors
bnchi Sep 20, 2024
51bb56a
Refactor join
bnchi Sep 20, 2024
8ff33fd
Refactor message
bnchi Sep 22, 2024
216ffd6
Update the message source
bnchi Sep 22, 2024
088fd7a
Add more blockquote tests
bnchi Sep 22, 2024
bc509ea
Complete blockquote tests
bnchi Sep 25, 2024
9bfa391
Add tests for list item
bnchi Sep 25, 2024
a288baa
Minor refactor
bnchi Sep 25, 2024
3312e38
Update CI jobs
bnchi Sep 25, 2024
2262c6e
Complete the tests for list_item
bnchi Oct 2, 2024
0785d36
Change comment
bnchi Oct 2, 2024
65751f8
Add tests for core
bnchi Oct 2, 2024
cfc6963
fix few test assertion message
bnchi Oct 2, 2024
aced8d4
Fix minor typo in bullet other check
bnchi Oct 2, 2024
ff12c7b
Add roundtrip tests
bnchi Oct 4, 2024
7786144
Update remove_pos
bnchi Oct 4, 2024
76f182f
Remove duplicate test
bnchi Oct 4, 2024
487225a
Minor refactor for list_item
bnchi Oct 4, 2024
cb4c81e
Fix typo
bnchi Oct 4, 2024
5faeb16
Add comments
bnchi Oct 5, 2024
c83247d
Add comments for construct names
bnchi Oct 5, 2024
82d8d90
Update comments
bnchi Oct 5, 2024
c73a56b
Update comments wrapping
bnchi Oct 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
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:
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ 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]]
name = "bench"
path = "benches/bench.rs"
Expand All @@ -31,14 +37,11 @@ serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies]
env_logger = "0.11"
criterion = "0.5"
pretty_assertions = "1"
pretty_assertions = { workspace = true }
serde_json = { version = "1" }
swc_core = { version = "0.100", features = [
"ecma_ast",
"ecma_visit",
"ecma_parser",
"common",
] }

[workspace]
members = ["generate"]
12 changes: 12 additions & 0 deletions mdast_util_to_markdown/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +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 }
37 changes: 37 additions & 0 deletions mdast_util_to_markdown/src/association.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use alloc::string::String;
use markdown::mdast::{Definition, ImageReference, LinkReference};

pub trait Association {
fn identifier(&self) -> &String;
fn label(&self) -> &Option<String>;
}

impl Association for Definition {
fn identifier(&self) -> &String {
&self.identifier
}

fn label(&self) -> &Option<String> {
&self.label
}
}

impl Association for ImageReference {
fn identifier(&self) -> &String {
&self.identifier
}

fn label(&self) -> &Option<String> {
&self.label
}
}

impl Association for LinkReference {
fn identifier(&self) -> &String {
&self.identifier
}

fn label(&self) -> &Option<String> {
&self.label
}
}
77 changes: 77 additions & 0 deletions mdast_util_to_markdown/src/configure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pub struct Options {
/// 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: '.').
pub bullet_ordered: char,
/// Marker to use for emphasis ('*' or '_', default: '*').
pub emphasis: char,
// 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.
pub fences: bool,
// How to indent the content of list items (default: 'IndentOptions::One').
pub list_item_indent: IndentOptions,
/// 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.
pub resource_link: bool,
/// 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.
pub setext: bool,
/// 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: '.',
emphasis: '*',
fence: '`',
fences: true,
increment_list_marker: true,
rule_repetition: 3,
list_item_indent: IndentOptions::One,
quote: '"',
rule: '*',
strong: '*',
close_atx: false,
rule_spaces: false,
resource_link: false,
setext: false,
tight_definitions: false,
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs some docs. Could be taken from mdast-util-to-markdown as well. See core of markdown-rs for info on how to do docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added comments here let me know if that's good enough

Loading