Skip to content

Commit

Permalink
feat: add markdown parser to CSAF notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 30, 2023
1 parent 2a68b6e commit aadc133
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
16 changes: 16 additions & 0 deletions spog/ui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spog/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gloo-utils = { version = "0.1", features = ["serde"] }
humansize = "2"
itertools = "0.11"
log = "0.4"
markdown = "1.0.0-alpha.11"
monaco = { version = "0.3", features = ["yew-components"] }
packageurl = "0.3"
patternfly-yew = { version = "0.5.0-alpha.3", features = ["icons-fab", "tree"] }
Expand Down
21 changes: 15 additions & 6 deletions spog/ui/src/components/advisory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ mod search;

pub use details::*;
pub use search::*;
use std::borrow::Cow;
use std::collections::HashSet;

use crate::{
backend::Endpoint,
components::{
common::CardWrapper, cvss::CvssMap, download::Download, severity::Severity, table_wrapper::TableWrapper,
common::CardWrapper, cvss::CvssMap, download::Download, markdown::Markdown, severity::Severity,
table_wrapper::TableWrapper,
},
hooks::use_backend,
pages::{AppRoute, View},
Expand All @@ -27,6 +26,8 @@ use csaf::{
};
use patternfly_yew::prelude::*;
use spog_model::prelude::*;
use std::borrow::Cow;
use std::collections::HashSet;
use std::rc::Rc;
use url::Url;
use yew::prelude::*;
Expand Down Expand Up @@ -238,9 +239,17 @@ pub fn csaf_notes(props: &CsafNotesProperties) -> Html {
html!(
<CardWrapper plain={props.plain} title="Notes">
<DescriptionList>
{ for props.notes.iter().flatten().map(|note| {
html!( <DescriptionGroup term={note_term(note).to_string()}> { &note.text } </DescriptionGroup> )
})}
{ for props.notes.iter().flatten().map(|note| {
html!(
<DescriptionGroup
term={note_term(note).to_string()}
>
<Content>
<Markdown content={Rc::new(note.text.clone())}/>
</Content>
</DescriptionGroup>
)
})}
</DescriptionList>
</CardWrapper>
)
Expand Down
22 changes: 22 additions & 0 deletions spog/ui/src/components/markdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::components::common::SafeHtml;
use std::rc::Rc;
use yew::prelude::*;

#[derive(PartialEq, Properties)]
pub struct MarkdownProperties {
pub content: Rc<String>,
}

#[function_component(Markdown)]
pub fn markdown(props: &MarkdownProperties) -> Html {
let content = use_memo(
|content| {
markdown::to_html_with_options(content.as_str(), &markdown::Options::gfm())
.map(AttrValue::from)
.unwrap_or_else(|_| AttrValue::from((*props.content).clone()))
},
props.content.clone(),
);

html!(<SafeHtml html={(*content).clone()}/>)
}
1 change: 1 addition & 0 deletions spog/ui/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod cvss;
pub mod download;
pub mod editor;
pub mod error;
pub mod markdown;
pub mod sbom;
pub mod search;
pub mod severity;
Expand Down

0 comments on commit aadc133

Please sign in to comment.