R8.4: ElyMark typesets inline formulas; \( and \[ read as math
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
10 files changed
+64
-15
No files matched your search
@@ -10,7 +10,7 @@ mod tests;
|
||||
|
||||
use std::{io, path::Path};
|
||||
|
||||
use ely_gpui_component::documents::markdown_options;
|
||||
use ely_gpui_component::documents::markdown_tree;
|
||||
|
||||
pub use files::{Format, Target, write};
|
||||
pub use pictures::{Pictures, picture_file};
|
||||
@@ -43,8 +43,7 @@ pub fn body(text: &str, beside: Option<&Path>, pictures: &Pictures) -> io::Resul
|
||||
|
||||
/// `text`'s body; `placed` keeps what it copied.
|
||||
fn page_of(text: &str, placed: &mut pictures::Placed) -> io::Result<Page> {
|
||||
let tree = markdown::to_mdast(text, &markdown_options())
|
||||
.map_err(|error| io::Error::other(error.to_string()))?;
|
||||
let tree = markdown_tree(text);
|
||||
let mut page = Page::default();
|
||||
html::write(&tree, text, placed, &mut page)?;
|
||||
log::info!(
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
use std::io;
|
||||
|
||||
use ely_gpui_component::documents::{
|
||||
MarkdownBlock, MarkdownReader, alert, is_toc, markdown_options,
|
||||
MarkdownBlock, MarkdownReader, alert, is_toc, markdown_tree,
|
||||
};
|
||||
use markdown::mdast::Node;
|
||||
|
||||
/// `text` as plain text, a blank line between blocks.
|
||||
pub fn plain(text: &str) -> io::Result<String> {
|
||||
let tree = markdown::to_mdast(text, &markdown_options())
|
||||
.map_err(|error| io::Error::other(error.to_string()))?;
|
||||
let tree = markdown_tree(text);
|
||||
let reader = MarkdownReader::joined(text, &tree);
|
||||
let mut blocks = Vec::new();
|
||||
// Alerts and `[toc]` live only at the root.
|
||||
@@ -75,7 +74,15 @@ fn block(reader: &MarkdownReader, node: &Node, blocks: &mut Vec<String>) {
|
||||
block(reader, child, blocks);
|
||||
}
|
||||
}
|
||||
Node::Paragraph(_) | Node::Heading(_) => blocks.push(words(reader, node)),
|
||||
Node::Paragraph(_) => {
|
||||
let mut read = Vec::new();
|
||||
reader.block(node, &mut read);
|
||||
match read.as_slice() {
|
||||
[MarkdownBlock::Math(tex)] => blocks.push(tex.clone()),
|
||||
_ => blocks.push(words(reader, node)),
|
||||
}
|
||||
}
|
||||
Node::Heading(_) => blocks.push(words(reader, node)),
|
||||
Node::Html(_) => {
|
||||
let mut read = Vec::new();
|
||||
reader.block(node, &mut read);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Exports read the file as the visual mode does (R4.4).
|
||||
|
||||
use super::{Pictures, page, plain};
|
||||
use crate::output::{Page, html::write, markdown_options, pictures::Placed};
|
||||
use crate::output::{Page, html::write, markdown_tree, pictures::Placed};
|
||||
|
||||
fn html(text: &str) -> String {
|
||||
page(text, None, &Pictures::Inline).html
|
||||
@@ -160,7 +160,7 @@ fn notes_under_deep_marks_write_in_linear_time() {
|
||||
"<b>".repeat(count),
|
||||
"x[^n] ".repeat(count)
|
||||
);
|
||||
let tree = markdown::to_mdast(&source, &markdown_options()).expect("parsed");
|
||||
let tree = markdown_tree(&source);
|
||||
let mut placed = Placed::new(None, &Pictures::Inline);
|
||||
let start = std::time::Instant::now();
|
||||
write(&tree, &source, &mut placed, &mut Page::default()).expect("written");
|
||||
@@ -237,3 +237,17 @@ fn a_soft_break_joins_in_exports_as_typora_exports_it() {
|
||||
assert!(page.contains("<p>你好 测试<br>end</p>"), "{page}");
|
||||
assert_eq!(text("你好\n测试\n"), "你好 测试\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tex_delimiters_export_as_formulas() {
|
||||
let source = r"a \(x^2\) b
|
||||
|
||||
\[
|
||||
y+1
|
||||
\]
|
||||
";
|
||||
let page = page(source, None, &Pictures::Inline);
|
||||
assert_eq!(page.html.matches("<svg").count(), 2, "{}", page.html);
|
||||
assert!(page.formulas.is_empty(), "{:?}", page.formulas);
|
||||
assert_eq!(text(source), "a x^2 b\n\ny+1\n");
|
||||
}
|
||||
Reference in new issue
Block a user