#let render_text(val) = {
let render_text_str(val) = {
let parse_url(value) = {
let regex_full_url = regex("(.*)\\\href\{([^\{]*?)\}\{(.*)\}(.*)")
let matched = value.match(regex_full_url)
if matched == none {
return value
}
let captures = matched.captures
let before = captures.at(0)
let url = captures.at(1)
let (url_link, after) = (captures.at(2), captures.at(3))
let url_link = render_text_str(url_link)
return before + "#link(\"" + url + "\")[" + url_link + "]" + after
}
let parse_textbf(val) = {
let regex_bf = regex("(.*)\\\\textbf\{([^\{]*?)\}(.*)")
let mat = val.match(regex_bf)
if mat == none {
return val
}
return mat.captures.at(0) + " *" + mat.captures.at(1) + "* " + mat.captures.at(2)
}
let remove_new_line(val_li) = {
return val_li.replace("\\newline", " \\ ")
}
let text = remove_new_line(val)
let text = parse_url(text)
let text = parse_textbf(text)
return text
}
let final_text = render_text_str(val)
eval(final_text, mode: "markup")
}
Could you please provide further explanation (maybe in OP) of what exact problem you have and what kind of help you want? I just see a big function definition with some LaTeX commands in strings. The title doesn’t make it clear what this is about, not 100%.
It is difficult for machine conversion to avoid human edits. How about converting the markup before writing the document? You’ll end up with a dependency-free *.typ, but need two binaries (pandoc+typst) to start, however.
If you want some features, you need the code. You can always take the package’s source code and put it in your project (with open source software at least – just be sure to respect the license) but I don’t really see the point in this – it pollutes your project with code that is not about the actual document, and gives you no benefits whatsoever over using the same code from the package.
(well, I can think of one benefit: it makes it a tiny bit easier to compile your code on a machine without internet connection. If that’s your concern, we can certainly help with that, without sacrificing one of Typst most convenient features)
It’s nowhere near node_modules. It’s better to use packages than hack your way around it. Makes it possible to keep the project lean, but also potentially have only one Typst file, which is very convenient to share/embed etc. In the endgame, you probably will need fewer packages, as Typst become much more complete.