Skip to content

Commit

Permalink
rm fmt_json
Browse files Browse the repository at this point in the history
The actual to-json is something I should think about harder and do
right, or not at all. The to-plaintext helper is now in fmt_str.

I had originally added the json formatting as a quick way of getting
some output, before I had good markdown rendering. I don't need that
shim anymore.
  • Loading branch information
yshavit committed Jun 16, 2024
1 parent bf6a175 commit 2ef56f9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 191 deletions.
180 changes: 0 additions & 180 deletions src/fmt_json.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use std::io;
use std::io::{stdin, Read};
use std::string::ToString;

use crate::fmt_json::TextOnly;
use crate::fmt_md::MdOptions;
use crate::output::Stream;
use crate::tree::MdqNode;

mod fmt_json;
mod fmt_md;
mod fmt_str;
mod output;
Expand All @@ -33,9 +31,6 @@ fn main() {

let found = selector.find(&mdq);

let jsons = fmt_json::nodes_to_json::<_, TextOnly>(&found);
println!("{}", jsons);
out.write_str("\n\n=======================================\n\n");
fmt_md::write_md(&MdOptions::default(), &mut out, &found);
out.write_str("\n");
}
8 changes: 2 additions & 6 deletions src/select.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::fmt_json;
use crate::fmt_str::inlines_to_plain_string;
use crate::tree::*;

#[allow(dead_code)]
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Selector {
MdqNode::Root(Root { body }) => SelectResult::Recurse(body),
MdqNode::Header(Header { title, body, .. }) => {
if let Selector::Heading(matcher) = self {
if matcher.matches(&Self::line_to_string(title)) {
if matcher.matches(&inlines_to_plain_string(title)) {
SelectResult::Found(body.iter().map(|elem| elem).collect())
} else {
SelectResult::Recurse(body)
Expand Down Expand Up @@ -145,8 +145,4 @@ impl Selector {
fn find_in_children<'a>(&'a self, children: &'a Vec<MdqNode>) -> Vec<&MdqNode> {
children.iter().flat_map(|elem| self.find(elem)).collect()
}

fn line_to_string(line: &[Inline]) -> String {
fmt_json::TextOnly::line_to_string(line)
}
}

0 comments on commit 2ef56f9

Please sign in to comment.