started on docs to markup to html

This commit is contained in:
Anton-4 2021-09-29 20:05:03 +02:00
parent 168c511988
commit 28cf11a1d9
11 changed files with 75 additions and 70 deletions

View file

@ -1,47 +1,12 @@
use crate::html::ToHtml;
use roc_parse::ast::Def;
use roc_code_markup::{markup::nodes::{MarkupNode}};
impl<'a> ToHtml<'a> for Def<'a> {
impl<'a> ToHtml<'a> for MarkupNode {
fn css_class(&self) -> Option<&'a str> {
match self {
// Def::Annotation(_, _) => {}
// Def::Alias { .. } => {}
Def::Body(_, _) => None,
// Def::AnnotatedBody { .. } => {}
// Def::Expect(_) => {}
Def::SpaceBefore(_, _) => None,
Def::SpaceAfter(_, _) => None,
// Def::NotYetImplemented(_) => {}
_ => None,
}
Some("operator")
}
fn html_body(&self, buf: &mut bumpalo::collections::String<'a>) {
match self {
// Def::Annotation(_, _) => {}
// Def::Alias { .. } => {}
Def::Body(pattern, expr) => {
pattern.html(buf);
EqualSign.html(buf);
expr.html(buf);
}
// Def::AnnotatedBody { .. } => {}
// Def::Expect(_) => {}
Def::SpaceBefore(sub_def, spaces) => {
for space in spaces.iter() {
space.html(buf);
}
sub_def.html(buf);
}
Def::SpaceAfter(sub_def, spaces) => {
sub_def.html(buf);
for space in spaces.iter() {
space.html(buf);
}
}
// Def::NotYetImplemented(_) => {}
_ => {}
}
buf.push_str("MarkupNode")
}
}

View file

@ -1,6 +1,10 @@
use crate::html::ToHtml;
use roc_parse::ast::{CommentOrNewline, Expr, StrLiteral, StrSegment};
use roc_region::all::Located;
use bumpalo::Bump;
use roc_ast::{ast_error::ASTResult, lang::{core::expr::expr_to_expr2::expr_to_expr2, env::Env, scope::Scope}, mem_pool::pool::Pool};
use roc_code_markup::{markup::nodes::expr2_to_markup, slow_pool::SlowPool};
use roc_module::symbol::Interns;
use roc_parse::ast::{Expr, StrLiteral};
use roc_region::all::{Located, Region};
impl<'a> ToHtml<'a> for Expr<'a> {
fn css_class(&self) -> Option<&'a str> {
@ -155,3 +159,35 @@ impl<'a> ToHtml<'a> for ParamComma {
buf.push_str(", ")
}
}
fn write_expr_to_bump_str_html<'a>(
arena: &mut Bump,
env: &mut Env<'a>,
scope: &mut Scope,
region: Region,
expr: &'a Expr,
interns: &Interns,
bump_str: &mut bumpalo::collections::String<'a>
) -> ASTResult<()> {
let (expr2, _) = expr_to_expr2(env, scope, expr, region);
let mut expr2_pool = Pool::with_capacity(1024);
let expr2_id = expr2_pool.add(expr2);
let mut mark_node_pool = SlowPool::default();
let expr2_markup_id = expr2_to_markup(
arena,
env,
&expr2,
expr2_id,
&mut mark_node_pool,
interns,
)?;
let expr2_markup_node = mark_node_pool.get(expr2_markup_id);
expr2_markup_node.html(bump_str);
Ok(())
}