Skip to content

Commit

Permalink
Define ast in wasi
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Jun 18, 2024
1 parent e373f16 commit 3810f49
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
# os: [ubuntu-latest, macos-latest, windows-latest]
# os: [macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v2
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ opt-level = "s"

[workspace.metadata.release]
push = false
tag = false
tag = false

[workspace.dependencies.notedown-wasi]
version = "0.0.*"
path = 'C:\Users\Dell\CLionProjects\notedown-rs\projects\notedown-wasi'
8 changes: 1 addition & 7 deletions projects/panduck-html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ license = "MPL-2.0"
edition = "2018"

[dependencies]
notedown_ast = "0.16.3"
notedown-error = "1.1.10"
notedown-wasi = { workspace = true }
html-escape = "0.2.11"
serde = { version = "1.0.144", features = ["derive"] }
merge = "0.1.0"
Expand All @@ -32,10 +31,5 @@ version = "0"
path = "../pretty-print"
features = []

[dev-dependencies.panduck-core]
version = "0.1.3"
path = "../panduck-core"
features = ["markdown"]

[features]
default = ["katex", "syntect"]
6 changes: 1 addition & 5 deletions projects/panduck-jupyter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ license = "MPL-2.0"
edition = "2018"

[dependencies]
notedown-wasi = { workspace = true }
serde_json = "1.0.115"

[dependencies.notedown-wasi]
version = "0.0.*"
#path = 'C:\Users\Dell\CLionProjects\notedown-rs\projects\notedown-wasi'
features = []

[features]
default = []
server = []
Expand Down
2 changes: 1 addition & 1 deletion projects/panduck-latex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MPL-2.0"
edition = "2021"

[dependencies]
notedown_ast = "0.16.3"
notedown-wasi = { workspace = true}
notedown-error = "1.1.10"
notedown-rt = "0.3.2"
serde = { version = "1.0.144", features = ["derive"] }
Expand Down
5 changes: 1 addition & 4 deletions projects/panduck-markdown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ license = "MPL-2.0"
edition = "2018"

[dependencies]
toml = "0.8.12"
notedown-wasi = { workspace = true, features = ["toml"]}
markdown = "1.0.0-alpha.16"
pandoc_ast = "0.8.6"

[dependencies.notedown-wasi]
version = "0.0.*"
#path = 'C:\Users\Dell\CLionProjects\notedown-rs\projects\notedown-wasi'


[features]
Expand Down
9 changes: 7 additions & 2 deletions projects/panduck-markdown/src/from_cmd/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use super::*;
use markdown::mdast::{Definition, FootnoteDefinition, Heading, Toml, Yaml};
use wasi_notedown::exports::notedown::core::syntax_tree::{CommandAction, HeadingBlock};

impl NoteBlockList for Vec<Node> {
fn note_down_block(self, state: &mut ReadState) -> Vec<RootItem> {
group_block(self, state)
}
}

impl NoteBlock for Node {
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> {
Expand Down Expand Up @@ -48,6 +52,7 @@ impl NoteBlock for Node {

impl NoteBlock for Toml {
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> {

Ok(RootItem::Placeholder)
}
}
Expand Down
35 changes: 15 additions & 20 deletions projects/panduck-markdown/src/from_cmd/inline.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use super::*;
use markdown::mdast::{FootnoteReference, Image, Link, MdxTextExpression};
use std::str::FromStr;
use wasi_notedown::{
exports::notedown::core::{
syntax_tree::{ImageReference, LinkReference},
types::Url,
},
UrlNative,
};
use wasi_notedown::exports::notedown::core::syntax_tree::CommandAction;
impl NoteInlineList for Vec<Node> {
fn note_down_inline(self, state: &mut ReadState) -> Vec<ParagraphItem> {
group_inline(self, state)
}
}

impl NoteInline for Node {
fn note_down_inline(self, state: &mut ReadState) -> Result<ParagraphItem, NotedownError> {
Expand Down Expand Up @@ -58,26 +53,26 @@ impl NoteInline for Text {
}
}

impl NoteInline for Strong {
impl NoteInline for Emphasis {
fn note_down_inline(self, state: &mut ReadState) -> Result<ParagraphItem, NotedownError> {
// let mut blocks = paragraph_items(self.children, state)?;
let text = StyledText { type_: StyleType::BOLD, range: self.position.as_range() };
let _ = self.children.note_down_inline(state);
let text = StyledText { type_: StyleType::ITALIC, range: self.position.as_range() };
Ok(ParagraphItem::Style(text))
}
}

impl NoteInline for Delete {
impl NoteInline for Strong {
fn note_down_inline(self, state: &mut ReadState) -> Result<ParagraphItem, NotedownError> {
// let mut blocks = paragraph_items(self.children, state)?;
let text = StyledText { type_: StyleType::ITALIC, range: self.position.as_range() };
let _ = self.children.note_down_inline(state);
let text = StyledText { type_: StyleType::BOLD, range: self.position.as_range() };
Ok(ParagraphItem::Style(text))
}
}

impl NoteInline for Emphasis {
fn note_down_inline(self, _: &mut ReadState) -> Result<ParagraphItem, NotedownError> {
// let mut blocks = paragraph_items(self.children, state)?;
let text = StyledText { type_: StyleType::ITALIC, range: self.position.as_range() };
impl NoteInline for Delete {
fn note_down_inline(self, state: &mut ReadState) -> Result<ParagraphItem, NotedownError> {
let _ = self.children.note_down_inline(state);
let text = StyledText { type_: StyleType::STRIKETHROUGH, range: self.position.as_range() };
Ok(ParagraphItem::Style(text))
}
}
Expand Down
2 changes: 1 addition & 1 deletion projects/panduck-markdown/src/from_cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ impl NoteBlock for List {
}

fn list_item(item: markdown::mdast::ListItem, state: &mut ReadState) -> Option<ListItem> {
let items = root_items(item.children, state).unwrap();
let items = item.children.note_down_block(state);
Some(ListItem { level: 0, checked: item.checked, range: item.position.as_range() })
}
61 changes: 23 additions & 38 deletions projects/panduck-markdown/src/from_cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
use crate::utils::{ root_items, GetTextRange, NoteBlock, NoteInline, NoteInlineList, NoteRoot, ReadState};
use crate::utils::{GetTextRange, group_block, group_inline, NoteBlock, NoteBlockList, NoteInline, NoteInlineList, NoteRoot, ReadState};
use markdown::{
mdast::{
BlockQuote, Code, Delete, Emphasis, InlineCode, InlineMath, List, Math, Node, Paragraph, Root, Strong, Table, Text,
BlockQuote, Code, Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Image, InlineCode,
InlineMath, Link, List, Math, MdxTextExpression, Node, Paragraph, Strong, Table, Text, Toml, Yaml,
},
to_mdast, Constructs, ParseOptions,
};
use wasi_notedown::exports::notedown::core::{
syntax_tree::{
CodeEnvironment, CodeHighlight, ListEnvironment, ListItem, MathContent, MathDisplay, MathEnvironment, NormalText,
NotedownRoot, ParagraphBlock, ParagraphItem, RootItem, StyleType, StyledText, TableCell, TableEnvironment, TableRow,
use std::str::FromStr;
use wasi_notedown::{
exports::notedown::core::{
syntax_tree::{
CodeEnvironment, CodeHighlight, CommandAction, HeadingBlock, ImageReference, LinkReference, ListEnvironment,
ListItem, MathContent, MathDisplay, MathEnvironment, NormalText, NotedownRoot, ParagraphBlock, ParagraphItem,
RootItem, StyleType, StyledText, TableCell, TableEnvironment, TableRow,
},
types::{NotedownError, TextRange, Url},
},
types::{NotedownError, Object, TextRange},
UrlNative,
};

mod blocks;
Expand Down Expand Up @@ -66,55 +72,34 @@ impl MarkdownParser {
mdx_jsx_text: true,
thematic_break: true,
},
gfm_strikethrough_single_tilde: false,
math_text_single_dollar: false,
gfm_strikethrough_single_tilde: true,
math_text_single_dollar: true,
mdx_expression_parse: None,
mdx_esm_parse: None,
};
let mut state = ReadState::default();
let root = match to_mdast(input, &config) {
Ok(to_mdast) => match to_mdast.note_down_root(&mut state) {
Ok(o) => o,
Err(e) => {
todo!()
}
},
Ok(to_mdast) => to_mdast.note_down_root(&mut state),
Err(e) => {
todo!()
todo!("{}", e)
}
};
Ok(root)
}
}

impl NoteRoot for Node {
fn note_down_root(self, state: &mut ReadState) -> Result<NotedownRoot, NotedownError> {
match self {
Self::Root(node) => node.note_down_root(state),
fn note_down_root(self, state: &mut ReadState) -> NotedownRoot {
let blocks = match self {
Self::Root(node) => node.children.note_down_block(state),
_ => unreachable!(),
}
};
NotedownRoot { blocks, config: state.get_object(), path: state.get_path() }
}
}

impl NoteRoot for Root {
fn note_down_root(self, state: &mut ReadState) -> Result<NotedownRoot, NotedownError> {
let blocks = root_items(self.children, state)?;
Ok(NotedownRoot { blocks, config: Object { map: vec![] }, path: None })
}
}

impl NoteInlineList for Vec<Node> {
fn note_down_inline(self, state: &mut ReadState) -> Vec<ParagraphItem> {
let mut items = Vec::with_capacity(self.len());
for x in self {
match x.note_down_inline(state) {
Ok(o) => items.push(o),
Err(e) => state.note_error(e),
}
}
items
}
}


#[test]
fn ready() {
Expand Down
42 changes: 23 additions & 19 deletions projects/panduck-markdown/src/from_pandoc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
use crate::utils::{NoteBlock, NoteInline, NoteInlineList, ReadState};
use crate::utils::{group_block, group_inline, NoteBlock, NoteBlockList, NoteInline, NoteInlineList, ReadState};
use pandoc_ast::{Block, Inline, MathType};
use std::str::FromStr;
use wasi_notedown::{
exports::notedown::core::{
syntax_tree::{
HeadingBlock, ImageReference, LinkReference, ParagraphBlock, ParagraphItem, RootItem, StyleType, StyledText,
CodeEnvironment, CommandAction, HeadingBlock, ImageReference, LinkReference, ParagraphBlock, ParagraphItem,
RootItem, StyleType, StyledText,
},
types::{NotedownError, TextRange, Url},
},
UrlNative,
};

impl NoteBlock for Vec<Block> {
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> {
todo!()
impl NoteBlockList for Vec<Block> {
fn note_down_block(self, state: &mut ReadState) -> Vec<RootItem> {
group_block(self, state)
}
}

#[allow(unused)]
impl NoteBlock for Block {
fn note_down_block(self, state: &mut ReadState) -> Result<RootItem, NotedownError> {
let item = match self {
Self::Plain(_) => {
unimplemented!()
}
Self::Para(v) => unimplemented!(),
Self::Div(_, children) => unimplemented!(),
Self::Div(attr, children) => {
unimplemented!()
},
Self::LineBlock(_) => {
unimplemented!()
}
Self::CodeBlock(attr, code) => unimplemented!(),
Self::CodeBlock(attr, code) => {
let code = CodeEnvironment {
action: CommandAction::Anonymous,
lines: code,
range: TextRange { head_offset: 0, tail_offset: 0 },
};
RootItem::Code(code)
}
Self::RawBlock(_, _) => {
unimplemented!()
}
Expand Down Expand Up @@ -56,14 +67,14 @@ impl NoteBlock for Block {
RootItem::Heading(heading)
}
Self::HorizontalRule => unimplemented!(),
Self::Table(_, _, _, _, _, _) => {
Self::Table(attr, _, _, _, _, _) => {
unimplemented!()
}
Self::Figure(_, _, _) => {
Self::Figure(attr, cap, children) => {
unimplemented!()
}
Self::Null => {
unimplemented!()
RootItem::Placeholder
}
};
Ok(item)
Expand All @@ -72,14 +83,7 @@ impl NoteBlock for Block {

impl NoteInlineList for Vec<Inline> {
fn note_down_inline(self, state: &mut ReadState) -> Vec<ParagraphItem> {
let mut list = Vec::with_capacity(self.len());
for item in self {
match item.note_down_inline(state) {
Ok(o) => list.push(o),
Err(e) => state.note_error(e),
}
}
list
group_inline(self, state)
}
}

Expand Down Expand Up @@ -157,4 +161,4 @@ fn make_styled(children: Vec<Inline>, state: &mut ReadState) -> ParagraphItem {
let items = children.note_down_inline(state);
let style = StyledText { type_: StyleType::UNDERLINE, range: TextRange { head_offset: 0, tail_offset: 0 } };
ParagraphItem::Style(style)
}
}
Loading

0 comments on commit 3810f49

Please sign in to comment.