typegen: insert newlines after callouts to avoid breaking new site
This commit is contained in:
parent
593634eb27
commit
34f0819a76
|
@ -648,8 +648,8 @@ fn parse_details(comment: Comment) -> String {
|
||||||
module: comment.module,
|
module: comment.module,
|
||||||
};
|
};
|
||||||
|
|
||||||
crate::reformat::GfmQuoteBlocks::reformat(&reformat_ctx, &mut str);
|
crate::reformat::GfmQuoteBlocks::new().reformat(&reformat_ctx, &mut str);
|
||||||
crate::reformat::TypeLinks::reformat(&reformat_ctx, &mut str);
|
crate::reformat::TypeLinks.reformat(&reformat_ctx, &mut str);
|
||||||
|
|
||||||
str
|
str
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,38 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use fancy_regex::Regex;
|
||||||
|
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
pub module: &'a str,
|
pub module: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ReformatPass {
|
pub trait ReformatPass {
|
||||||
fn reformat(context: &Context, text: &mut String);
|
fn reformat(&self, context: &Context, text: &mut String);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GfmQuoteBlocks;
|
pub struct GfmQuoteBlocks {
|
||||||
|
callout_regex: Regex,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GfmQuoteBlocks {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
callout_regex: Regex::new(r#">\s+\[!(?<type>\w+)]\s+(?=\w)"#).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ReformatPass for GfmQuoteBlocks {
|
impl ReformatPass for GfmQuoteBlocks {
|
||||||
fn reformat(_: &Context, text: &mut String) {
|
fn reformat(&self, _: &Context, text: &mut String) {
|
||||||
*text = text.replace("> [!INFO]", "> [!NOTE]");
|
*text = text.replace("> [!INFO]", "> [!NOTE]");
|
||||||
|
*text = self.callout_regex.replace_all(text, "> [!$type]\n> ").to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TypeLinks;
|
pub struct TypeLinks;
|
||||||
|
|
||||||
impl ReformatPass for TypeLinks {
|
impl ReformatPass for TypeLinks {
|
||||||
fn reformat(context: &Context, text: &mut String) {
|
fn reformat(&self ,context: &Context, text: &mut String) {
|
||||||
let lines = text.lines().map(|line| {
|
let lines = text.lines().map(|line| {
|
||||||
if line.contains("@@") {
|
if line.contains("@@") {
|
||||||
let mut src: &str = &*line;
|
let mut src: &str = &*line;
|
||||||
|
|
Loading…
Reference in a new issue