mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 12:46:43 +00:00
fix: clean typlite markers from doc strings (#2017)
When there's HTML comments in list, the markdown syntax won't be parsed as expected. This pr cleans typlite markers from doc string to avoid this behavior. <img width="654" height="223" alt="bfedf840bc92a34c44212006232a7e17" src="https://github.com/user-attachments/assets/9015952b-a5de-4d59-a8ff-61a5e3d09d1b" /> <img width="641" height="257" alt="0267db904824cf09b67234bdcb0919e7" src="https://github.com/user-attachments/assets/938fabaa-d6fe-42d4-adca-6c96b59443e2" />
This commit is contained in:
parent
14c7a92944
commit
7a9e1cfb3c
4 changed files with 27 additions and 21 deletions
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
mod def;
|
mod def;
|
||||||
pub use def::*;
|
pub use def::*;
|
||||||
mod tidy;
|
pub mod tidy;
|
||||||
pub use tidy::*;
|
pub use tidy::*;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,13 @@ pub struct TidyModuleDocs {
|
||||||
pub docs: EcoString,
|
pub docs: EcoString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_list_annotations(s: &str) -> String {
|
||||||
|
static REG: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(|| {
|
||||||
|
regex::Regex::new(r"<!-- typlite:(?:begin|end):[\w\-]+ \d+ -->").unwrap()
|
||||||
|
});
|
||||||
|
REG.replace_all(s, "").to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn identify_pat_docs(converted: &str) -> StrResult<TidyPatDocs> {
|
pub fn identify_pat_docs(converted: &str) -> StrResult<TidyPatDocs> {
|
||||||
let lines = converted.lines().collect::<Vec<_>>();
|
let lines = converted.lines().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
@ -120,7 +127,7 @@ pub fn identify_pat_docs(converted: &str) -> StrResult<TidyPatDocs> {
|
||||||
name: param_line.0,
|
name: param_line.0,
|
||||||
types: param_line.1,
|
types: param_line.1,
|
||||||
default: None,
|
default: None,
|
||||||
docs: buf.into_iter().join("\n").into(),
|
docs: remove_list_annotations(&buf.into_iter().join("\n")).into(),
|
||||||
});
|
});
|
||||||
break_line = Some(line_width);
|
break_line = Some(line_width);
|
||||||
|
|
||||||
|
|
@ -129,8 +136,10 @@ pub fn identify_pat_docs(converted: &str) -> StrResult<TidyPatDocs> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let docs = match break_line {
|
let docs = match break_line {
|
||||||
Some(line_no) => (lines[..line_no]).iter().copied().join("\n").into(),
|
Some(line_no) => {
|
||||||
None => converted.into(),
|
remove_list_annotations(&(lines[..line_no]).iter().copied().join("\n")).into()
|
||||||
|
}
|
||||||
|
None => remove_list_annotations(converted).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
params.reverse();
|
params.reverse();
|
||||||
|
|
@ -142,7 +151,9 @@ pub fn identify_pat_docs(converted: &str) -> StrResult<TidyPatDocs> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn identify_tidy_module_docs(docs: EcoString) -> StrResult<TidyModuleDocs> {
|
pub fn identify_tidy_module_docs(docs: EcoString) -> StrResult<TidyModuleDocs> {
|
||||||
Ok(TidyModuleDocs { docs })
|
Ok(TidyModuleDocs {
|
||||||
|
docs: remove_list_annotations(&docs).into(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_brace(trim_start: &str) -> Option<(&str, &str)> {
|
fn match_brace(trim_start: &str) -> Option<(&str, &str)> {
|
||||||
|
|
@ -224,9 +235,9 @@ See show-module() for outputting the results of this function.
|
||||||
-> string"###), @r"
|
-> string"###), @r"
|
||||||
>> docs:
|
>> docs:
|
||||||
These again are dictionaries with the keys
|
These again are dictionaries with the keys
|
||||||
- <!-- typlite:begin:list-item 0 -->`description` (optional): The description for the argument.<!-- typlite:end:list-item 0 -->
|
- `description` (optional): The description for the argument.
|
||||||
- <!-- typlite:begin:list-item 0 -->`types` (optional): A list of accepted argument types.<!-- typlite:end:list-item 0 -->
|
- `types` (optional): A list of accepted argument types.
|
||||||
- <!-- typlite:begin:list-item 0 -->`default` (optional): Default value for this argument.<!-- typlite:end:list-item 0 -->
|
- `default` (optional): Default value for this argument.
|
||||||
|
|
||||||
See show-module() for outputting the results of this function.
|
See show-module() for outputting the results of this function.
|
||||||
<< docs
|
<< docs
|
||||||
|
|
@ -273,7 +284,7 @@ See show-module() for outputting the results of this function.
|
||||||
-> string"###), @r"
|
-> string"###), @r"
|
||||||
>> docs:
|
>> docs:
|
||||||
These again are dictionaries with the keys
|
These again are dictionaries with the keys
|
||||||
- <!-- typlite:begin:list-item 0 -->`description` (optional): The description for the argument.<!-- typlite:end:list-item 0 -->
|
- `description` (optional): The description for the argument.
|
||||||
|
|
||||||
See show-module() for outputting the results of this function.
|
See show-module() for outputting the results of this function.
|
||||||
<< docs
|
<< docs
|
||||||
|
|
@ -286,8 +297,8 @@ See show-module() for outputting the results of this function.
|
||||||
>>arg label-prefix: auto, string
|
>>arg label-prefix: auto, string
|
||||||
The label-prefix for internal function
|
The label-prefix for internal function
|
||||||
references. If `auto`, the label-prefix name will be the module name.
|
references. If `auto`, the label-prefix name will be the module name.
|
||||||
- <!-- typlite:begin:list-item 1 -->nested something<!-- typlite:end:list-item 1 -->
|
- nested something
|
||||||
- <!-- typlite:begin:list-item 1 -->nested something 2<!-- typlite:end:list-item 1 -->
|
- nested something 2
|
||||||
<< arg
|
<< arg
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ use crate::docs::{file_id_repr, module_docs, DefDocs, PackageDefInfo};
|
||||||
use crate::package::{get_manifest_id, PackageInfo};
|
use crate::package::{get_manifest_id, PackageInfo};
|
||||||
use crate::LocalContext;
|
use crate::LocalContext;
|
||||||
|
|
||||||
|
use tinymist_analysis::docs::tidy::remove_list_annotations;
|
||||||
|
|
||||||
/// Generate full documents in markdown format
|
/// Generate full documents in markdown format
|
||||||
pub fn package_docs(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<String> {
|
pub fn package_docs(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<String> {
|
||||||
log::info!("generate_md_docs {spec:?}");
|
log::info!("generate_md_docs {spec:?}");
|
||||||
|
|
@ -338,14 +340,6 @@ struct ConvertResult {
|
||||||
errors: Vec<String>,
|
errors: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_list_annotations(s: &str) -> String {
|
|
||||||
let s = s.to_string();
|
|
||||||
static REG: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(|| {
|
|
||||||
regex::Regex::new(r"<!-- typlite:(?:begin|end):[\w\-]+ \d+ -->").unwrap()
|
|
||||||
});
|
|
||||||
REG.replace_all(&s, "").to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use tinymist_world::package::{PackageRegistry, PackageSpec};
|
use tinymist_world::package::{PackageRegistry, PackageSpec};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
source: crates/tinymist-query/src/hover.rs
|
source: crates/tinymist-query/src/hover.rs
|
||||||
expression: content
|
expression: content
|
||||||
input_file: crates/tinymist-query/src/fixtures/hover/render_equation.typ
|
input_file: crates/tinymist-query/src/fixtures/hover/render_equation.typ
|
||||||
|
snapshot_kind: text
|
||||||
---
|
---
|
||||||
Range: 12:20:12:23
|
Range: 12:20:12:23
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ type: type
|
||||||
```
|
```
|
||||||
|
|
||||||
The type of the argument.
|
The type of the argument.
|
||||||
- <!-- typlite:begin:list-item 1 -->It can be also regarded as the condition of the proposition.<!-- typlite:end:list-item 1 -->
|
- It can be also regarded as the condition of the proposition.
|
||||||
|
|
||||||
## B (positional)
|
## B (positional)
|
||||||
|
|
||||||
|
|
@ -40,4 +41,4 @@ type: type
|
||||||
```
|
```
|
||||||
|
|
||||||
The type of the body.
|
The type of the body.
|
||||||
- <!-- typlite:begin:list-item 1 -->It can be also regarded as the conclusion of the proposition.<!-- typlite:end:list-item 1 -->
|
- It can be also regarded as the conclusion of the proposition.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue