mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
markup to html progress
This commit is contained in:
parent
f63c276a5f
commit
bc50280c0e
2 changed files with 62 additions and 9 deletions
|
@ -6,15 +6,6 @@ use roc_parse::ast::{Expr, StrLiteral};
|
||||||
use roc_region::all::{Region};
|
use roc_region::all::{Region};
|
||||||
use roc_code_markup::{markup::nodes::{MarkupNode}};
|
use roc_code_markup::{markup::nodes::{MarkupNode}};
|
||||||
|
|
||||||
impl<'a> ToHtml<'a> for MarkupNode {
|
|
||||||
fn css_class(&self) -> Option<&'a str> {
|
|
||||||
Some("operator")
|
|
||||||
}
|
|
||||||
fn html_body(&self, buf: &mut bumpalo::collections::String<'a>) {
|
|
||||||
buf.push_str("MarkupNode")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ToHtml<'a> for Expr<'a> {
|
impl<'a> ToHtml<'a> for Expr<'a> {
|
||||||
fn css_class(&self) -> Option<&'a str> {
|
fn css_class(&self) -> Option<&'a str> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
use roc_code_markup::{markup::nodes::MarkupNode, slow_pool::SlowPool};
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
|
use bumpalo::{collections::String as BumpString};
|
||||||
|
|
||||||
pub trait ToHtml<'a> {
|
pub trait ToHtml<'a> {
|
||||||
fn css_class(&self) -> Option<&'a str>;
|
fn css_class(&self) -> Option<&'a str>;
|
||||||
|
@ -43,3 +45,63 @@ where
|
||||||
self.value.html(buf);
|
self.value.html(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// determine appropriate css class for MarkupNode
|
||||||
|
fn mark_node_html<'a>(mark_node: &MarkupNode, mark_node_pool: &SlowPool, buf: &mut bumpalo::collections::String<'a>) {
|
||||||
|
match mark_node {
|
||||||
|
MarkupNode::Nested { children_ids, newlines_at_end, .. } => {
|
||||||
|
for &child_id in children_ids {
|
||||||
|
mark_node_html(
|
||||||
|
mark_node_pool.get(child_id),
|
||||||
|
mark_node_pool,
|
||||||
|
buf
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _ in 0..*newlines_at_end {
|
||||||
|
buf.push('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MarkupNode::Text { syn_high_style, newlines_at_end, .. } => {
|
||||||
|
use HighlightStyle::*;
|
||||||
|
|
||||||
|
let css_class = match syn_high_style {
|
||||||
|
Operator => "operator",
|
||||||
|
String => "string",
|
||||||
|
FunctionName => "function_name",
|
||||||
|
Type => "type",
|
||||||
|
Bracket => "bracket",
|
||||||
|
Number => "number",
|
||||||
|
PackageRelated => "package-related",
|
||||||
|
Variable => "variable",
|
||||||
|
RecordField => "recordfield",
|
||||||
|
Import => "import",
|
||||||
|
Provides => "provides",
|
||||||
|
Blank => "blank",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
MarkupNode::Blank { syn_high_style, newlines_at_end, .. } => {
|
||||||
|
let mut content_str = " ".to_string();
|
||||||
|
|
||||||
|
for _ in 0..*newlines_at_end {
|
||||||
|
content_str.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
write_html_to_buf(content_str, "blank", buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_html_to_buf<'a>(content: String, css_class: &'static str, buf: &mut BumpString<'a>) {
|
||||||
|
|
||||||
|
let opening_tag: String = ["<span class=\"syntax-", css_class, "\">"].concat();
|
||||||
|
|
||||||
|
buf.push_str(opening_tag.as_str());
|
||||||
|
|
||||||
|
buf.push_str(&content);
|
||||||
|
|
||||||
|
buf.push_str("</span>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue