Skip to content
Permalink
Browse files

latex

  • Loading branch information
adamdruppe committed May 6, 2016
1 parent df731a0 commit 3b949b0bf171fbb2577bdceaa2f9f8121075f4b7
Showing with 105 additions and 27 deletions.
  1. +1 −1 Makefile
  2. +20 −14 comment.d
  3. +21 −12 doc2.d
  4. +63 −0 latex.d
@@ -7,5 +7,5 @@ DSYMBOL_COMPONENTS=Dscanner/dsymbol/src/dsymbol/scope_.d Dscanner/dsymbol/src/ds

all:
#dmd diff.d terminal.d $(LIBDPARSE)
dmd -m64 doc2.d comment.d stemmer.d dom.d -J. $(LIBDPARSE) -g # -debug=verbose
dmd -m64 doc2.d latex.d cgi.d comment.d stemmer.d dom.d -J. $(LIBDPARSE) -g # -debug=verbose
#dmd -of/var/www/dpldocs.info/locate locate.d dom stemmer.d cgi -J. -version=fastcgi -m64 -debug
@@ -93,6 +93,7 @@ struct DocComment {
string examples;
string diagnostics;
string throws;
string bugs;
string see_alsos;

string[string] otherSections;
@@ -157,8 +158,9 @@ struct DocComment {
}


output.putTag("<div class=\"documentation-comment\">");
output.putTag(formatDocumentationComment(param[split + 1 .. $], decl));
output.putTag("</dd>");
output.putTag("</div></dd>");
}
output.putTag("</dl>");
}
@@ -211,6 +213,14 @@ struct DocComment {
output.putTag("</div>");
}

if(bugs.strip.length) {
output.putTag("<h2 id=\"bugs\">Bugs</h2>");
output.putTag("<div class=\"documentation-comment bugs-description\">");
output.putTag(formatDocumentationComment(throws, decl));
output.putTag("</div>");
}


if(examples.length || utInfo.length) {
output.putTag("<h2 id=\"examples\"><a href=\"#examples\" class=\"header-anchor\">Examples</a></h2>");
output.putTag(formatDocumentationComment(examples, decl));
@@ -235,7 +245,7 @@ struct DocComment {
}

foreach(section, content; otherSections) {
output.putTag("<div class=\"" ~ section ~ "-section other-section\">");
output.putTag("<div class=\"documentation-comment " ~ section ~ "-section other-section\">");
output.putTag("<h3>");
output.put(section.capitalize);
output.putTag("</h3>");
@@ -511,6 +521,9 @@ DocComment parseDocumentationComment(string comment, Decl decl) {
case "throws":
c.throws ~= line ~ "\n";
break;
case "bugs":
c.bugs ~= line ~ "\n";
break;
case "authors":
case "license":
case "source":
@@ -1378,20 +1391,13 @@ Element expandDdocMacros2(string txt, Decl decl) {
return translateList(stuff, decl, "ol");
}

/+
if(name == "MATH") {
/*
a^(n+b)
log_2(4)
y = mx+b
(4+3)/4
*/
auto holder = Element.make("div", "", "user-math");
// FIXME do some ascii string to html thing
return holder;
import adrdox.latex;
auto got = mathToImgHtml(stuff);
if(got is null)
return Element.make("span", stuff, "user-math-render-failed");
return got;
}
+/

if(name == "ADRDOX_SAMPLE") {
// show the original source as code
33 doc2.d
@@ -27,6 +27,17 @@ import std.conv : to;

enum skip_undocumented = true;

static bool sorter(Decl a, Decl b) {
if(a.declarationType == b.declarationType)
return a.name < b.name;
else if(a.declarationType == "module" || b.declarationType == "module") // always put modules up top
return
(a.declarationType == "module" ? "aaaaaa" : a.declarationType)
< (b.declarationType == "module" ? "aaaaaa" : b.declarationType);
else
return a.declarationType < b.declarationType;
}

void annotatedPrototype(T)(T decl, MyOutputRange output) {
auto classDec = decl.astNode;

@@ -565,8 +576,15 @@ Document writeHtml(Decl decl, bool forReal = true) {

if(members.length) {
content.addChild("h2", "Members").id = "members";
auto dl = content.addChild("dl").addClass("member-list native");
foreach(child; members) {
Element dl;
string lastType;
foreach(child; members.sort!sorter) {
if(child.declarationType != lastType) {
content.addChild("h3", pluralize(child.declarationType).capitalize);
dl = content.addChild("dl").addClass("member-list native");
lastType = child.declarationType;
}

handleChildDecl(dl, child);

writeHtml(child);
@@ -668,16 +686,7 @@ Document writeHtml(Decl decl, bool forReal = true) {
}

import std.algorithm;
static bool sorter(Decl a, Decl b) {
if(a.declarationType == b.declarationType)
return a.name < b.name;
else if(a.declarationType == "module" || b.declarationType == "module") // always put modules up top
return
(a.declarationType == "module" ? "aaaaaa" : a.declarationType)
< (b.declarationType == "module" ? "aaaaaa" : b.declarationType);
else
return a.declarationType < b.declarationType;
}

sort!sorter(navArray);

Element list;
63 latex.d
@@ -0,0 +1,63 @@
module adrdox.latex;

import std.process;
import std.file;

import arsd.dom;

// requires latex and dvipng to be installed on your system already, it just
// calls out to them in the shell
Element mathToImgHtml(string mathCode) {

string dir = tempDir;

// FIXME: this should prolly be unique or somethign
string filebase = "./adrdox";

std.file.write(dir ~ "/" ~ filebase ~ ".latex",
`\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{empty}
\begin{document}
$ `~mathCode~` $
\end{document}`
);

auto tpl = executeShell(
"latex -interaction=nonstopmode " ~ filebase ~ ".latex"
~ " && " ~
"dvipng -T tight -D 200 -o "~filebase~".png -bg Transparent "~filebase~".dvi -z 9",
null, Config.none, size_t.max, dir
);

if(tpl.status != 0)
return null;


auto prefix = dir ~ "/" ~ filebase;
if(exists(prefix ~ ".aux"))
remove(prefix ~ ".aux");
if(exists(prefix ~ ".dvi"))
remove(prefix ~ ".dvi");
if(exists(prefix ~ ".latex"))
remove(prefix ~ ".latex");
if(exists(prefix ~ ".log"))
remove(prefix ~ ".log");

if(exists(prefix ~ ".png")) {
auto file = read(prefix ~ ".png");
remove(prefix ~ ".png");

import arsd.cgi;
auto img = Element.make("img");
img.alt = mathCode;
img.src = makeDataUrl("image/png", file);
img.className = "rendered-math";
return img;
}

return null;

}

0 comments on commit 3b949b0

Please sign in to comment.
You can’t perform that action at this time.