aboutsummaryrefslogtreecommitdiffstats
path: root/src/mdast.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-28 17:54:39 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-28 17:55:44 +0200
commitb33a81e40620b8b3eaeeec9d0e0b34ca5958dead (patch)
treec91e56db38777b30cdcef591d0f7cd9bd1ac0ee8 /src/mdast.rs
parenta0c84c505d733be2e987a333a34244c1befb56cb (diff)
downloadmarkdown-rs-b33a81e40620b8b3eaeeec9d0e0b34ca5958dead.tar.gz
markdown-rs-b33a81e40620b8b3eaeeec9d0e0b34ca5958dead.tar.bz2
markdown-rs-b33a81e40620b8b3eaeeec9d0e0b34ca5958dead.zip
Add support for turning mdast to hast
Diffstat (limited to 'src/mdast.rs')
-rw-r--r--src/mdast.rs77
1 files changed, 5 insertions, 72 deletions
diff --git a/src/mdast.rs b/src/mdast.rs
index 79a39dd..8b5b74d 100644
--- a/src/mdast.rs
+++ b/src/mdast.rs
@@ -1,83 +1,14 @@
-//! [mdast][] syntax tree.
+//! markdown syntax tree: [mdast][].
//!
//! [mdast]: https://github.com/syntax-tree/mdast
+use crate::unist::Position;
use alloc::{
fmt,
string::{String, ToString},
vec::Vec,
};
-/// One place in a source file.
-#[derive(Clone, Eq, PartialEq)]
-pub struct Point {
- /// 1-indexed integer representing a line in a source file.
- pub line: usize,
- /// 1-indexed integer representing a column in a source file.
- pub column: usize,
- /// 0-indexed integer representing a character in a source file.
- pub offset: usize,
-}
-
-impl Point {
- #[must_use]
- pub fn new(line: usize, column: usize, offset: usize) -> Point {
- Point {
- line,
- column,
- offset,
- }
- }
-}
-
-impl fmt::Debug for Point {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}:{} ({})", self.line, self.column, self.offset)
- }
-}
-
-/// Location of a node in a source file.
-#[derive(Clone, Eq, PartialEq)]
-pub struct Position {
- /// Represents the place of the first character of the parsed source region.
- pub start: Point,
- /// Represents the place of the first character after the parsed source
- /// region, whether it exists or not.
- pub end: Point,
-}
-
-impl Position {
- #[must_use]
- pub fn new(
- start_line: usize,
- start_column: usize,
- start_offset: usize,
- end_line: usize,
- end_column: usize,
- end_offset: usize,
- ) -> Position {
- Position {
- start: Point::new(start_line, start_column, start_offset),
- end: Point::new(end_line, end_column, end_offset),
- }
- }
-}
-
-impl fmt::Debug for Position {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "{}:{}-{}:{} ({}-{})",
- self.start.line,
- self.start.column,
- self.end.line,
- self.end.column,
- self.start.offset,
- self.end.offset
- )
- }
-}
-
/// Explicitness of a reference.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReferenceKind {
@@ -370,7 +301,8 @@ impl Node {
}
}
- pub fn position(&mut self) -> Option<&Position> {
+ #[must_use]
+ pub fn position(&self) -> Option<&Position> {
match self {
Node::Root(x) => x.position.as_ref(),
Node::BlockQuote(x) => x.position.as_ref(),
@@ -1204,6 +1136,7 @@ pub struct MdxJsxAttribute {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::unist::{Point, Position};
use alloc::{string::ToString, vec};
#[test]