Skip to content

Commit

Permalink
Merge pull request #149 from abap34/feat/#129
Browse files Browse the repository at this point in the history
脚注の完全なサポート
  • Loading branch information
abap34 authored Aug 7, 2024
2 parents d9a5bd6 + c03cd31 commit f5a9769
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,14 @@ iframe {
a {
color: #007bff;
word-break: break-all;
}

.footnote {
border-top: solid 1px #555;
font-style: italic;
}

.footnote > * {
display: block;
margin-bottom: 10px;
}
11 changes: 11 additions & 0 deletions src/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,15 @@ iframe {
a {
color: #007bff;
word-break: break-all;
}

.footnote {
border-top: solid 1px #ddd;
font-style: italic;
color: #777;
}


.footnote > * {
display: block;
}
19 changes: 19 additions & 0 deletions src/render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,23 @@ namespace almo {
return output_html;
}

void move_footnote_definition(Markdown& ast) {
std::vector<std::shared_ptr<ASTNode>> footnote_defs = ast.nodes_byclass("FootnoteDefinition");

std::shared_ptr<DivBlock> footnote_div = std::make_shared<DivBlock>("footnote");

ast.pushback_child(footnote_div);

for (auto node : footnote_defs) {
ast.move_node(node, footnote_div);
}
}

std::string render(Markdown ast, std::map<std::string, std::string> meta_data) {
std::vector<std::shared_ptr<ASTNode>> footnote_defs = ast.nodes_byclass("FootnoteDefinition");

std::shared_ptr<DivBlock> footnote_div = std::make_shared<DivBlock>("footnote");

std::string content = ast.to_html();

std::string html_template = load_html_template(meta_data["template_file"], meta_data["css_setting"], meta_data["required_pyodide"] == "true");
Expand Down Expand Up @@ -148,6 +164,9 @@ namespace almo {
Markdown ast;
MarkdownParser parser(md_content);
parser.process(ast);

move_footnote_definition(ast);

render(ast, meta_data);
ParseSummary summary = {
.ast = ast,
Expand Down
13 changes: 6 additions & 7 deletions src/syntax/FootnoteDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
namespace almo {
struct FootnoteDefinition : public ASTNode {
private:
std::string tag;
std::string symbol;

public:
FootnoteDefinition(std::string tag_) : tag(tag_) { set_uuid(); }
FootnoteDefinition(std::string symbol_) : symbol(symbol_) { set_uuid(); }
std::string to_html() const override {
std::string childs_html = concatenated_childs_html();
return "<span class=\"footnote_def\"> <li id=\"note_" + tag +
"\"><a href=\"#ref_" + tag + "\">^" + tag + "</a>" +
childs_html + "</li> </span>";
return "<span class=\"footnote-def\"><a href=\"#ref_" + symbol + "\">^" +
symbol + "</a>" + childs_html + "</span>";
}
std::map<std::string, std::string> get_properties() const override {
return {{"tag", tag}};
return {{"symbol", symbol}};
}
std::string get_classname() const override { return "FootnoteDefinition"; }
};

struct FootnoteDefinitionSyntax : public BlockSyntax {
/*
"[^" + expr + "]: + hoge"
"[^" + symbol + "]: + hoge"
*/
static inline const std::regex rex = std::regex(R"(\[\^(.*?)\]:(.*?))");
bool operator()(Reader &read) const override {
Expand Down

0 comments on commit f5a9769

Please sign in to comment.