mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
feat: import_context
and contexual convert (#1816)
* feat: impl import_context * dev: fmt, clippy * fix: update import path handling to use rootless paths and normalize separators * feat: fix errors for fletcher v0.5.8 --------- Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
This commit is contained in:
parent
9d9d360db9
commit
a24c516148
5 changed files with 74 additions and 11 deletions
|
@ -159,6 +159,8 @@ pub struct TypliteFeat {
|
|||
pub remove_html: bool,
|
||||
/// The target to convert
|
||||
pub target: Format,
|
||||
/// Import context for code examples (e.g., "#import \"/path/to/file.typ\": *")
|
||||
pub import_context: Option<String>,
|
||||
}
|
||||
|
||||
/// Task builder for converting a typst document to Markdown.
|
||||
|
|
|
@ -256,16 +256,23 @@ impl HtmlToAstParser {
|
|||
|
||||
const PRELUDE: &str = r##"#set page(width: auto, height: auto, margin: (y: 0.45em, rest: 0em), fill: none);
|
||||
#set text(fill: rgb("#c0caf5")) if sys.inputs.at("x-color-theme", default: none) == "dark";"##;
|
||||
|
||||
let import_prefix = if let Some(ref import_ctx) = self.feat.import_context {
|
||||
format!("{}\n", import_ctx)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
world
|
||||
.map_shadow_by_id(
|
||||
main,
|
||||
Bytes::from_string(match mode.as_str() {
|
||||
"code" => eco_format!("{PRELUDE}#{{{src}}}"),
|
||||
"math" => eco_format!("{PRELUDE}${src}$"),
|
||||
"markup" => eco_format!("{PRELUDE}#[{}]", src),
|
||||
"code" => eco_format!("{}{PRELUDE}#{{{src}}}", import_prefix),
|
||||
"math" => eco_format!("{}{PRELUDE}${src}$", import_prefix),
|
||||
"markup" => eco_format!("{}{PRELUDE}#[{}]", import_prefix, src),
|
||||
// todo check mode
|
||||
// "markup" |
|
||||
_ => eco_format!("{PRELUDE}#[{}]", src),
|
||||
_ => eco_format!("{}{PRELUDE}#[{}]", import_prefix, src),
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue