├── examples ├── matrix-calculus │ ├── matrix-calculus.json │ └── images │ │ ├── neuron.png │ │ ├── chain-tree.png │ │ ├── plus-square.png │ │ ├── sin-square.png │ │ └── not-equal-icon.png └── simple │ ├── book.xml │ ├── chap2.xml │ ├── chap1.xml │ └── css │ └── book.css ├── images ├── snapshot.png ├── snapshot2.png ├── snapshot-df.png ├── snapshot-graph.png ├── snapshot-print.png ├── xT.svg └── dfdx.svg ├── oldsrc └── us │ └── parr │ └── bookish │ ├── model │ ├── OutputModelObject.java │ ├── LineBreak.java │ ├── EqnVecVar.java │ ├── Bold.java │ ├── TODO.java │ ├── Other.java │ ├── Italics.java │ ├── BlockCode.java │ ├── XMLEndTag.java │ ├── EqnVar.java │ ├── InlineCode.java │ ├── InlineImage.java │ ├── EqnIndexedVecVar.java │ ├── ref │ │ ├── SiteRef.java │ │ ├── FigureRef.java │ │ ├── ChapterRef.java │ │ ├── SectionRef.java │ │ ├── CitationRef.java │ │ ├── SideNoteRef.java │ │ ├── SideQuoteRef.java │ │ ├── UnknownRef.java │ │ └── EntityRef.java │ ├── ModelElement.java │ ├── SectionHeader.java │ ├── UnOrderedList.java │ ├── Callout.java │ ├── entity │ │ ├── UnknownDef.java │ │ ├── SubSectionDef.java │ │ ├── SubSubSectionDef.java │ │ ├── SideFigDef.java │ │ ├── ChapQuoteDef.java │ │ ├── SideNoteDef.java │ │ ├── FigureDef.java │ │ ├── PyEvalDef.java │ │ ├── SiteDef.java │ │ ├── SideQuoteDef.java │ │ ├── CitationDef.java │ │ ├── InlinePyEvalDef.java │ │ ├── PyFigDef.java │ │ ├── EntityWithScope.java │ │ ├── ChapterDef.java │ │ ├── SectionDef.java │ │ ├── ExecutableCodeDef.java │ │ └── EntityDef.java │ ├── Site.java │ ├── Author.java │ ├── EqnIndexedVar.java │ ├── HyperLink.java │ ├── TableRow.java │ ├── OrderedList.java │ ├── Quoted.java │ ├── Abstract.java │ ├── TableItem.java │ ├── PreAbstract.java │ ├── Latex.java │ ├── XMLTag.java │ ├── ChapQuote.java │ ├── BlockEquation.java │ ├── TextBlock.java │ ├── Aside.java │ ├── Table.java │ ├── SideNote.java │ ├── InlinePyEval.java │ ├── ListItem.java │ ├── Citation.java │ ├── SideQuote.java │ ├── BlockImage.java │ ├── PyFig.java │ ├── PyEval.java │ ├── Join.java │ ├── Article.java │ ├── SideFigure.java │ ├── SubSection.java │ ├── SubSubSection.java │ ├── TableHeaderItem.java │ ├── PyEvalDataFrame.java │ ├── Paragraph.java │ ├── InlineEquation.java │ ├── PyDo.java │ ├── ContainerWithTitle.java │ ├── Section.java │ ├── Document.java │ ├── Book.java │ ├── Image.java │ └── Chapter.java │ ├── parse │ ├── XML.g4 │ └── BookishLexer.g4 │ ├── translate │ ├── LatexEscaper.java │ ├── Tex2SVG.java │ └── ModelConverter.java │ └── util │ └── DataTable.java ├── src └── us │ └── parr │ └── bookish │ ├── model │ ├── LineBreak.java │ ├── OutputModelObject.java │ ├── EqnVecVar.java │ ├── Bold.java │ ├── TODO.java │ ├── Text.java │ ├── Italics.java │ ├── RawHTML.java │ ├── BlockCode.java │ ├── EqnVar.java │ ├── InlineCode.java │ ├── InlineImage.java │ ├── EqnIndexedVecVar.java │ ├── ModelElement.java │ ├── UnOrderedList.java │ ├── ref │ │ ├── SiteRef.java │ │ ├── ChapterRef.java │ │ ├── FigureRef.java │ │ ├── SectionRef.java │ │ ├── CalloutRef.java │ │ ├── CitationRef.java │ │ ├── SideNoteRef.java │ │ ├── SideQuoteRef.java │ │ ├── UnknownRef.java │ │ ├── EntityRef.java │ │ └── Figure.java │ ├── SectionHeader.java │ ├── Callout.java │ ├── Site.java │ ├── UnknownSymbol.java │ ├── Author.java │ ├── Citation.java │ ├── EqnIndexedVar.java │ ├── HyperLink.java │ ├── TableRow.java │ ├── ChapQuote.java │ ├── OrderedList.java │ ├── Quoted.java │ ├── Abstract.java │ ├── TableItem.java │ ├── SideFigure.java │ ├── PreAbstract.java │ ├── Latex.java │ ├── SubSubSection.java │ ├── BlockEquation.java │ ├── TextBlock.java │ ├── Table.java │ ├── SideNote.java │ ├── Aside.java │ ├── SideQuote.java │ ├── ArticleFile.java │ ├── YouTube.java │ ├── SubSection.java │ ├── InlinePyEval.java │ ├── ListItem.java │ ├── Section.java │ ├── BlockImage.java │ ├── PyFig.java │ ├── PyEval.java │ ├── Join.java │ ├── ContainerWithTitle.java │ ├── PyEvalDataFrame.java │ ├── Paragraph.java │ ├── TableHeaderItem.java │ ├── BookFrontMatterFile.java │ ├── InlineEquation.java │ ├── PyDo.java │ ├── Chapter.java │ └── Image.java │ ├── entity │ ├── SideFigDef.java │ ├── BookDef.java │ ├── ArticleDef.java │ ├── SubSectionDef.java │ ├── SideNoteDef.java │ ├── SubSubSectionDef.java │ ├── ChapQuoteDef.java │ ├── FigureDef.java │ ├── ChapterDef.java │ ├── SectionDef.java │ ├── UnknownDef.java │ ├── SiteDef.java │ ├── SideQuoteDef.java │ ├── PyEvalDef.java │ ├── CalloutDef.java │ ├── CitationDef.java │ ├── PyFigDef.java │ ├── EntityWithScope.java │ ├── InlinePyEvalDef.java │ ├── ExecutableCodeDef.java │ └── EntityDef.java │ ├── semantics │ ├── Book.java │ ├── Article.java │ ├── BookishBaseListener.java │ ├── ArtifactListener.java │ ├── Artifact.java │ ├── DefPythonEntitiesListener.java │ ├── Tex2SVG.java │ ├── DefEntitiesListener.java │ └── ConvertLatexToImageListener.java │ ├── translate │ ├── LatexEscaper.java │ ├── HTMLEscaper.java │ └── ModelConverter.java │ ├── parse │ ├── ChapDocInfo.java │ ├── RootDocInfo.java │ ├── DocInfo.java │ ├── BookishLexer.g4 │ └── BookishParser.g4 │ └── util │ └── DataTable.java ├── resources └── templates │ ├── html-article.stg │ ├── eqntex.stg │ ├── pyeval.stg │ └── latex-article.stg ├── .gitignore ├── bin └── article.sh ├── LICENSE.txt └── pom.xml /examples/matrix-calculus/matrix-calculus.json: -------------------------------------------------------------------------------- 1 | { 2 | "files":["matrix-calculus.md"] 3 | } 4 | -------------------------------------------------------------------------------- /images/snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/images/snapshot.png -------------------------------------------------------------------------------- /images/snapshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/images/snapshot2.png -------------------------------------------------------------------------------- /images/snapshot-df.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/images/snapshot-df.png -------------------------------------------------------------------------------- /images/snapshot-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/images/snapshot-graph.png -------------------------------------------------------------------------------- /images/snapshot-print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/images/snapshot-print.png -------------------------------------------------------------------------------- /examples/simple/book.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/matrix-calculus/images/neuron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/examples/matrix-calculus/images/neuron.png -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/OutputModelObject.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public abstract class OutputModelObject { 4 | } 5 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/LineBreak.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class LineBreak extends OutputModelObject { 4 | } 5 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/OutputModelObject.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public abstract class OutputModelObject { 4 | } 5 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/LineBreak.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class LineBreak extends OutputModelObject { 4 | } 5 | -------------------------------------------------------------------------------- /examples/matrix-calculus/images/chain-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/examples/matrix-calculus/images/chain-tree.png -------------------------------------------------------------------------------- /examples/matrix-calculus/images/plus-square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/examples/matrix-calculus/images/plus-square.png -------------------------------------------------------------------------------- /examples/matrix-calculus/images/sin-square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/examples/matrix-calculus/images/sin-square.png -------------------------------------------------------------------------------- /examples/matrix-calculus/images/not-equal-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pietroppeter/bookish/master/examples/matrix-calculus/images/not-equal-icon.png -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/EqnVecVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnVecVar extends EqnVar { 4 | public EqnVecVar(String varname) { 5 | super(varname); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/EqnVecVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnVecVar extends EqnVar { 4 | public EqnVecVar(String varname) { 5 | super(varname); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /resources/templates/html-article.stg: -------------------------------------------------------------------------------- 1 | delimiters "$","$" 2 | 3 | import "html-book.stg" 4 | 5 | // these are not imported for some reason 6 | symbols ::= [ 7 | "copyright":"©", 8 | "tm":"™" 9 | ] 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Bold.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Bold extends OutputModelObject { 4 | public String text; 5 | 6 | public Bold(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/TODO.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class TODO extends OutputModelObject { 4 | public String text; 5 | 6 | public TODO(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Bold.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Bold extends OutputModelObject { 4 | public String text; 5 | 6 | public Bold(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/TODO.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class TODO extends OutputModelObject { 4 | public String text; 5 | 6 | public TODO(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Text.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Text extends OutputModelObject { 4 | public String text; 5 | 6 | public Text(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Other.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Other extends OutputModelObject { 4 | public String text; 5 | 6 | public Other(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Italics.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Italics extends OutputModelObject { 4 | public String text; 5 | 6 | public Italics(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/RawHTML.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class RawHTML extends OutputModelObject { 4 | public String html; 5 | 6 | public RawHTML(String html) { 7 | this.html = html; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Italics.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Italics extends OutputModelObject { 4 | public String text; 5 | 6 | public Italics(String text) { 7 | this.text = text; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/BlockCode.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class BlockCode extends OutputModelObject { 4 | public String code; 5 | 6 | public BlockCode(String code) { 7 | this.code = code; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/XMLEndTag.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class XMLEndTag extends OutputModelObject { 4 | public String name; 5 | 6 | public XMLEndTag(String name) { 7 | this.name = name; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/BlockCode.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class BlockCode extends OutputModelObject { 4 | public String code; 5 | 6 | public BlockCode(String code) { 7 | this.code = code; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/EqnVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnVar extends OutputModelObject { 4 | public String varname; 5 | 6 | public EqnVar(String varname) { 7 | this.varname = varname; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/InlineCode.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineCode extends OutputModelObject { 4 | public String code; 5 | 6 | public InlineCode(String code) { 7 | this.code = code; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/InlineImage.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineImage extends OutputModelObject { 4 | public String src; 5 | 6 | public InlineImage(String src) { 7 | this.src = src; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/EqnVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnVar extends OutputModelObject { 4 | public String varname; 5 | 6 | public EqnVar(String varname) { 7 | this.varname = varname; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/InlineCode.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineCode extends OutputModelObject { 4 | public String code; 5 | 6 | public InlineCode(String code) { 7 | this.code = code; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/InlineImage.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineImage extends OutputModelObject { 4 | public String src; 5 | 6 | public InlineImage(String src) { 7 | this.src = src; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/EqnIndexedVecVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnIndexedVecVar extends EqnIndexedVar { 4 | public EqnIndexedVecVar(String varname, String indexname) { 5 | super(varname, indexname); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/EqnIndexedVecVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnIndexedVecVar extends EqnIndexedVar { 4 | public EqnIndexedVecVar(String varname, String indexname) { 5 | super(varname, indexname); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/SiteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SiteRef extends EntityRef { 6 | public SiteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ModelElement.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | @Retention(RetentionPolicy.RUNTIME) 7 | public @interface ModelElement { 8 | } 9 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/UnOrderedList.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class UnOrderedList extends OrderedList { 6 | public UnOrderedList(List items) { 7 | super(items); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/SiteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SiteRef extends EntityRef { 6 | public SiteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ModelElement.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | @Retention(RetentionPolicy.RUNTIME) 7 | public @interface ModelElement { 8 | } 9 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SectionHeader.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class SectionHeader extends OutputModelObject { 4 | public String title; 5 | 6 | public SectionHeader(String title) { 7 | this.title = title; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/UnOrderedList.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class UnOrderedList extends OrderedList { 6 | public UnOrderedList(List items) { 7 | super(items); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/FigureRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class FigureRef extends EntityRef { 6 | public FigureRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SectionHeader.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class SectionHeader extends OutputModelObject { 4 | public String title; 5 | 6 | public SectionHeader(String title) { 7 | this.title = title; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/ChapterRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class ChapterRef extends EntityRef { 6 | public ChapterRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/FigureRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class FigureRef extends EntityRef { 6 | public FigureRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/SectionRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SectionRef extends EntityRef { 6 | public SectionRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Callout.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Callout extends OutputModelObject { 4 | @ModelElement 5 | public TextBlock text; 6 | 7 | public Callout(TextBlock text) { 8 | this.text = text; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/ChapterRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class ChapterRef extends EntityRef { 6 | public ChapterRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/SectionRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SectionRef extends EntityRef { 6 | public SectionRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/CalloutRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class CalloutRef extends SideNoteRef { 6 | public CalloutRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/CitationRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class CitationRef extends EntityRef { 6 | public CitationRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/SideNoteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideNoteRef extends EntityRef { 6 | public SideNoteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/UnknownDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | public class UnknownDef extends EntityDef { 6 | public UnknownDef(Token startToken) { 7 | super(0, startToken); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/CitationRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class CitationRef extends EntityRef { 6 | public CitationRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/SideNoteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideNoteRef extends EntityRef { 6 | public SideNoteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/SideQuoteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideQuoteRef extends EntityRef { 6 | public SideQuoteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/SideQuoteRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideQuoteRef extends EntityRef { 6 | public SideQuoteRef(EntityDef def) { 7 | super(def); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Callout.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class Callout extends SideNote { 6 | public Callout(EntityDef def, OutputModelObject text) { 7 | super(def, text); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Site.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.SiteDef; 4 | 5 | public class Site extends OutputModelObject { 6 | public SiteDef def; 7 | 8 | public Site(SiteDef def) { 9 | this.def = def; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Site.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.SiteDef; 4 | 5 | public class Site extends OutputModelObject { 6 | public SiteDef def; 7 | 8 | public Site(SiteDef def) { 9 | this.def = def; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/UnknownSymbol.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class UnknownSymbol extends OutputModelObject { 4 | public String symbolName; 5 | 6 | public UnknownSymbol(String symbolName) { 7 | this.symbolName = symbolName; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Author.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Author extends OutputModelObject { 4 | @ModelElement 5 | public OutputModelObject author; 6 | 7 | public Author(OutputModelObject author) { 8 | this.author = author; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Author.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class Author extends OutputModelObject { 4 | @ModelElement 5 | public OutputModelObject author; 6 | 7 | public Author(OutputModelObject author) { 8 | this.author = author; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Citation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.CitationDef; 4 | 5 | public class Citation extends OutputModelObject { 6 | public CitationDef def; 7 | 8 | public Citation(CitationDef def) { 9 | this.def = def; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/EqnIndexedVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnIndexedVar extends EqnVar { 4 | public String indexname; 5 | 6 | public EqnIndexedVar(String varname, String indexname) { 7 | super(varname); 8 | this.indexname = indexname; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/EqnIndexedVar.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class EqnIndexedVar extends EqnVar { 4 | public String indexname; 5 | 6 | public EqnIndexedVar(String varname, String indexname) { 7 | super(varname); 8 | this.indexname = indexname; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/HyperLink.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class HyperLink extends OutputModelObject { 4 | public String title; 5 | public String href; 6 | 7 | public HyperLink(String title, String href) { 8 | this.title = title; 9 | this.href = href; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/HyperLink.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class HyperLink extends OutputModelObject { 4 | public String title; 5 | public String href; 6 | 7 | public HyperLink(String title, String href) { 8 | this.title = title; 9 | this.href = href; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/TableRow.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class TableRow extends OutputModelObject { 6 | @ModelElement 7 | public List items; 8 | 9 | public TableRow(List items) { 10 | this.items = items; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/TableRow.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class TableRow extends OutputModelObject { 6 | @ModelElement 7 | public List items; 8 | 9 | public TableRow(List items) { 10 | this.items = items; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ChapQuote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class ChapQuote extends OutputModelObject { 4 | public String quote; 5 | public String author; 6 | 7 | public ChapQuote(String quote, String author) { 8 | this.quote = quote; 9 | this.author = author; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/OrderedList.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class OrderedList extends OutputModelObject { 6 | @ModelElement 7 | public List items; 8 | 9 | public OrderedList(List items) { 10 | this.items = items; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/UnknownRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.entity.UnknownDef; 5 | 6 | public class UnknownRef extends EntityRef { 7 | public UnknownRef(Token startToken) { 8 | super(new UnknownDef(startToken)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/OrderedList.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class OrderedList extends OutputModelObject { 6 | @ModelElement 7 | public List items; 8 | 9 | public OrderedList(List items) { 10 | this.items = items; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/UnknownRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.entity.UnknownDef; 5 | 6 | public class UnknownRef extends EntityRef { 7 | public UnknownRef(Token startToken) { 8 | super(new UnknownDef(startToken)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/simple/chap2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Something nice 4 | 5 | Ref to previous chap is [intro]. 6 | 7 | 8 | import pandas as pd 9 | df = pd.DataFrame({"a":[1,2,3]}) 10 | 11 | 12 | Some 432 inline code. 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Quoted.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Quoted extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public Quoted(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Quoted.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Quoted extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public Quoted(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Abstract.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Abstract extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public Abstract(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Abstract.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Abstract extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public Abstract(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/TableItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class TableItem extends OutputModelObject { 6 | @ModelElement 7 | public List contents; 8 | 9 | public TableItem(List contents) { 10 | this.contents = contents; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/TableItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class TableItem extends OutputModelObject { 6 | @ModelElement 7 | public List contents; 8 | 9 | public TableItem(List contents) { 10 | this.contents = contents; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SideFigure.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | import us.parr.bookish.model.ref.Figure; 5 | 6 | public class SideFigure extends Figure { 7 | public SideFigure(EntityDef def, String label, OutputModelObject code) { 8 | super(def, label, code); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/PreAbstract.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class PreAbstract extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public PreAbstract(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SubSectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | public class SubSectionDef extends SectionDef { 6 | public SubSectionDef(int secNumber, Token titleToken, EntityWithScope enclosingScope) { 7 | super(secNumber, titleToken, enclosingScope); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/PreAbstract.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class PreAbstract extends OutputModelObject { 6 | @ModelElement 7 | public List elements; 8 | 9 | public PreAbstract(List elements) { 10 | this.elements = elements; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SubSubSectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | public class SubSubSectionDef extends SectionDef { 6 | public SubSubSectionDef(int secNumber, Token titleToken, EntityWithScope enclosingScope) { 7 | super(secNumber, titleToken, enclosingScope); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ref/EntityRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.model.OutputModelObject; 4 | import us.parr.bookish.entity.EntityDef; 5 | 6 | public class EntityRef extends OutputModelObject { 7 | public EntityDef def; 8 | 9 | public EntityRef(EntityDef def) { 10 | this.def = def; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SideFigDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SideFigDef extends FigureDef { 6 | public SideFigDef(int index, BookishParser.AttrsContext attrsCtx) { 7 | super(index, attrsCtx); 8 | } 9 | 10 | public boolean isSideItem() { return true; } 11 | } 12 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/EntityRef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | import us.parr.bookish.model.OutputModelObject; 5 | 6 | public class EntityRef extends OutputModelObject { 7 | public EntityDef def; 8 | 9 | public EntityRef(EntityDef def) { 10 | this.def = def; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Latex.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | public class Latex extends BlockImage { 6 | public String text; 7 | 8 | public Latex(Translator translator, String src, String alt, String text) { 9 | super(translator, src, alt); 10 | this.text = text; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/XMLTag.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Map; 4 | 5 | public class XMLTag extends OutputModelObject { 6 | public String name; 7 | public Map attrs; 8 | 9 | public XMLTag(String name, Map attrs) { 10 | this.name = name; 11 | this.attrs = attrs; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Latex.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | public class Latex extends BlockImage { 6 | public String text; 7 | 8 | public Latex(Translator translator, String src, String alt, String text) { 9 | super(translator, src, alt); 10 | this.text = text; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ChapQuote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class ChapQuote extends OutputModelObject { 4 | @ModelElement 5 | public TextBlock quote; 6 | 7 | @ModelElement 8 | public TextBlock author; 9 | 10 | public ChapQuote(TextBlock quote, TextBlock author) { 11 | this.quote = quote; 12 | this.author = author; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SubSubSection.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SubSubSection extends SubSection { 6 | public SubSubSection(EntityDef def, 7 | String title, 8 | OutputModelObject content) 9 | { 10 | super(def, title, content, null); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/BlockEquation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | public class BlockEquation extends BlockImage { 6 | public String eqn; 7 | 8 | public BlockEquation(Translator translator, String imageFilename, String eqn) { 9 | super(translator, imageFilename, ""); 10 | this.eqn = eqn; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/TextBlock.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | /** A block of {...} text in curlies */ 6 | public class TextBlock extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public TextBlock(List elements) { 11 | this.elements = elements; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/BlockEquation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | public class BlockEquation extends BlockImage { 6 | public String eqn; 7 | 8 | public BlockEquation(Translator translator, String imageFilename, String eqn) { 9 | super(translator, imageFilename, ""); 10 | this.eqn = eqn; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/TextBlock.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | /** A block of {...} text in curlies */ 6 | public class TextBlock extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public TextBlock(List elements) { 11 | this.elements = elements; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/BookDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class BookDef extends EntityWithScope { 6 | public BookDef(int index, 7 | BookishParser.AttrsContext attrsCtx, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(index, attrsCtx, enclosingScope); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Table.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Table extends OutputModelObject { 6 | @ModelElement 7 | public TableRow headers; 8 | @ModelElement 9 | public List rows; 10 | 11 | public Table(TableRow headers, List rows) { 12 | this.headers = headers; 13 | this.rows = rows; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Aside.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Map; 4 | 5 | public class Aside extends OutputModelObject { 6 | @ModelElement 7 | public TextBlock text; 8 | 9 | public Map attributes; 10 | 11 | public Aside(TextBlock text, Map attributes) { 12 | this.text = text; 13 | this.attrs = attrs; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Table.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | 5 | public class Table extends OutputModelObject { 6 | @ModelElement 7 | public TableRow headers; 8 | @ModelElement 9 | public List rows; 10 | 11 | public Table(TableRow headers, List rows) { 12 | this.headers = headers; 13 | this.rows = rows; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SideNote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideNote extends OutputModelObject { 6 | @ModelElement 7 | public OutputModelObject text; 8 | 9 | public EntityDef def; 10 | 11 | public SideNote(EntityDef def, OutputModelObject text) { 12 | this.text = text; 13 | this.def = def; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SideFigDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | import java.util.Map; 6 | 7 | public class SideFigDef extends FigureDef { 8 | public SideFigDef(int index, Token startToken, Map args) { 9 | super(index, startToken, args); 10 | } 11 | 12 | public boolean isSideItem() { return true; } 13 | } 14 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/ArticleDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class ArticleDef extends EntityWithScope { 6 | public ArticleDef(int index, 7 | BookishParser.AttrsContext attrsCtx, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(index, attrsCtx, enclosingScope); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Aside.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Map; 4 | 5 | public class Aside extends OutputModelObject { 6 | @ModelElement 7 | public OutputModelObject text; 8 | 9 | public Map attributes; 10 | 11 | public Aside(OutputModelObject text, Map attributes) { 12 | this.text = text; 13 | this.attributes = attributes; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SideQuote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.SideQuoteDef; 4 | 5 | import java.util.Map; 6 | 7 | public class SideQuote extends OutputModelObject { 8 | public SideQuoteDef def; 9 | 10 | public Map attributes; 11 | 12 | public SideQuote(SideQuoteDef def) { 13 | this.def = def; 14 | this.attributes = def.attributes; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bin/article.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "java -jar /Users/parrt/github/bookish/target/bookish-1.0-SNAPSHOT.jar -target html-article -o /tmp/gradient-boosting $1" 4 | java -jar /Users/parrt/github/bookish/target/bookish-1.0-SNAPSHOT.jar -target html -o /tmp/gradient-boosting $1 5 | 6 | #java -jar /Users/parrt/github/bookish/target/bookish-1.0-SNAPSHOT.jar -target html -o /tmp/mlbook /Users/parrt/github/mlbook-private/content/book.json 7 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SubSectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SubSectionDef extends SectionDef { 6 | public SubSectionDef(int secNumber, 7 | BookishParser.SubsectionContext ctx, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(secNumber, ctx.attrs(), enclosingScope); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ArticleFile.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.semantics.Article; 4 | 5 | // todo: delete. don't gen main page for article 6 | public class ArticleFile extends OutputModelObject { 7 | public Article article; 8 | 9 | public ArticleFile(Article article) { 10 | this.article = article; 11 | } 12 | 13 | public String getTitle() { return article.title; } 14 | } 15 | -------------------------------------------------------------------------------- /examples/simple/chap1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | some text *foo* and `this` is cool. Ref to [summary] forward ref. 4 | 5 |
6 | 7 | 8 | print("hi from chap1") 9 | x = 1 10 | 11 | 12 | An $x^2$ eqn and latex: 13 | 14 | 15 | latex input 16 | 17 | 18 | a block: 19 | 20 | \[ 21 | dy/dt = 3 22 | \] 23 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SideNoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SideNoteDef extends EntityDef { 6 | public String note; 7 | 8 | public SideNoteDef(int index, BookishParser.AttrsContext attrsCtx, String note) { 9 | super(index, attrsCtx.attributes); 10 | this.note = note; 11 | } 12 | 13 | public boolean isSideItem() { return true; } 14 | } 15 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SubSubSectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SubSubSectionDef extends SectionDef { 6 | public SubSubSectionDef(int secNumber, 7 | BookishParser.SubsubsectionContext ctx, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(secNumber, ctx.attrs(), enclosingScope); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/YouTube.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Map; 4 | 5 | public class YouTube extends OutputModelObject { 6 | public String src; 7 | public String width; 8 | public String height; 9 | 10 | public YouTube(Map attributes) { 11 | this.src = attributes.get("src"); 12 | this.width = attributes.get("width"); 13 | this.height = attributes.get("height"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/ChapQuoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | public class ChapQuoteDef extends EntityDef { 6 | public String quote; 7 | public String author; 8 | 9 | public ChapQuoteDef(String quote, String author) { 10 | super(0,null); 11 | this.quote = Translator.stripCurlies(quote); 12 | this.author = Translator.stripCurlies(author); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/ChapQuoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class ChapQuoteDef extends EntityDef { 6 | public String quote; 7 | public String author; 8 | 9 | public ChapQuoteDef(BookishParser.AttrsContext attrsCtx) { 10 | super(0, attrsCtx.attributes); 11 | this.quote = attributes.get("quote"); 12 | this.author = attributes.get("author"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/FigureDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class FigureDef extends EntityDef { 6 | public String caption; 7 | 8 | public FigureDef(int index, BookishParser.AttrsContext attrsCtx) { 9 | super(index, attrsCtx.attributes); 10 | this.caption = attributes.get("caption"); 11 | } 12 | 13 | public boolean isGloballyVisible() { return true; } 14 | } 15 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SideNote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideNote extends OutputModelObject { 6 | @ModelElement 7 | public TextBlock text; 8 | 9 | public String label; 10 | 11 | public EntityDef def; 12 | 13 | public SideNote(EntityDef def, String label, TextBlock text) { 14 | this.text = text; 15 | this.label = label; 16 | this.def = def; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/SubSection.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public class SubSection extends Section { 8 | public SubSection(EntityDef def, 9 | String title, 10 | OutputModelObject content, 11 | List subsections) 12 | { 13 | super(def, title, content, subsections); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/ChapterDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class ChapterDef extends EntityWithScope { 6 | public ChapterDef(int chapNumber, 7 | BookishParser.ChapterContext ctx, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(chapNumber, ctx.attrs(), enclosingScope); 11 | } 12 | 13 | public boolean isGloballyVisible() { return true; } 14 | } 15 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SideNoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | public class SideNoteDef extends EntityDef { 7 | public String note; 8 | 9 | public SideNoteDef(int index, Token startToken, String note) { 10 | super(index, startToken); 11 | this.note = Translator.stripCurlies(note); 12 | } 13 | 14 | public boolean isSideItem() { return true; } 15 | } 16 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SectionDef extends EntityWithScope { 6 | public SectionDef(int secNumber, 7 | BookishParser.AttrsContext attrsContext, 8 | EntityWithScope enclosingScope) 9 | { 10 | super(secNumber, attrsContext, enclosingScope); 11 | } 12 | 13 | public boolean isGloballyVisible() { return true; } 14 | } 15 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/InlinePyEval.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | public class InlinePyEval extends PyEval { 6 | public InlinePyEval(ExecutableCodeDef codeDef, 7 | String stdout, 8 | String stderr, 9 | String dataType, 10 | String displayData) 11 | { 12 | super(codeDef, stdout, stderr, null, dataType, displayData); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/InlinePyEval.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | public class InlinePyEval extends PyEval { 6 | public InlinePyEval(ExecutableCodeDef codeDef, 7 | String stdout, 8 | String stderr, 9 | String dataType, 10 | String displayData) 11 | { 12 | super(codeDef, stdout, stderr, null, dataType, displayData); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ListItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ListItem extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public ListItem(List elements) { 11 | this.elements = elements; 12 | } 13 | 14 | public ListItem(OutputModelObject element) { 15 | elements = new ArrayList<>(); 16 | elements.add(element); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/UnknownDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | import static us.parr.lib.ParrtStrings.stripQuotes; 6 | 7 | public class UnknownDef extends EntityDef { 8 | public Token startToken; 9 | public UnknownDef(Token startToken) { 10 | super(0,null, startToken); 11 | this.label = stripQuotes(startToken.getText()); 12 | } 13 | 14 | @Override 15 | public Token getStartToken() { 16 | return startToken; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ListItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ListItem extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public ListItem(List elements) { 11 | this.elements = elements; 12 | } 13 | 14 | public ListItem(OutputModelObject element) { 15 | elements = new ArrayList<>(); 16 | elements.add(element); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SiteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SiteDef extends EntityDef { 6 | public String website; 7 | 8 | public SiteDef(int index, BookishParser.AttrsContext attrsCtx) { 9 | super(index, attrsCtx.attributes); 10 | this.website = attrsCtx.attributes.get("url"); 11 | } 12 | 13 | public boolean isGloballyVisible() { return true; } 14 | 15 | public boolean isSideItem() { return true; } 16 | } 17 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/FigureDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | import java.util.Map; 6 | 7 | public class FigureDef extends EntityDef { 8 | public String caption; 9 | 10 | public FigureDef(int index, Token startToken, Map args) { 11 | super(index, startToken); 12 | this.label = args.get("label"); 13 | this.caption = args.get("caption"); 14 | } 15 | 16 | public boolean isGloballyVisible() { return true; } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/SideQuoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class SideQuoteDef extends EntityDef { 6 | public String quote; 7 | public String author; 8 | 9 | public SideQuoteDef(int index, BookishParser.AttrsContext attrsCtx) { 10 | super(index, attrsCtx.attributes); 11 | this.quote = attributes.get("quote"); 12 | this.author = attributes.get("author"); 13 | } 14 | 15 | public boolean isSideItem() { return true; } 16 | } 17 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/PyEvalDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import us.parr.bookish.parse.BookishParser; 5 | 6 | public class PyEvalDef extends ExecutableCodeDef { 7 | public PyEvalDef(ParserRuleContext tree, 8 | String inputFilename, 9 | int index, 10 | BookishParser.AttrsContext attrsCtx, 11 | String code) 12 | { 13 | super(tree, inputFilename, index, attrsCtx, code); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/PyEvalDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | 5 | import java.util.Map; 6 | 7 | public class PyEvalDef extends ExecutableCodeDef { 8 | public PyEvalDef(ParserRuleContext tree, 9 | String inputFilename, 10 | int index, 11 | Map attributes, 12 | String code) 13 | { 14 | super(tree, inputFilename, index, tree.getStart(), attributes, code); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SiteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | public class SiteDef extends EntityDef { 7 | public String website; 8 | 9 | public SiteDef(int index, Token startToken, String website) { 10 | super(index, startToken); 11 | this.website = Translator.stripCurlies(website); 12 | } 13 | 14 | public boolean isGloballyVisible() { return true; } 15 | 16 | public boolean isSideItem() { return true; } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/CalloutDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | /** These only appear to right of paragraphs like sidenotes. Must be 6 | * referenced to appear but ref itself is not shown in paragraph. it is 7 | * just there to identify which paragraph to associate with callout. 8 | */ 9 | public class CalloutDef extends SideNoteDef { 10 | public CalloutDef(int index, BookishParser.AttrsContext attrsCtx, String note) { 11 | super(index, attrsCtx, note); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Section.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public class Section extends ContainerWithTitle { 8 | public Section(EntityDef def, 9 | String title, 10 | OutputModelObject content, 11 | List subsections) 12 | { 13 | super(def, title, content); 14 | this.subcontainers = subsections; 15 | } 16 | 17 | public String getAnchor() { 18 | return def.label; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Citation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class Citation extends OutputModelObject { 6 | @ModelElement 7 | public TextBlock title; 8 | 9 | @ModelElement 10 | public TextBlock bibinfo; 11 | 12 | public String label; 13 | public EntityDef def; 14 | 15 | public Citation(EntityDef def, String label, TextBlock title, TextBlock bibinfo) { 16 | this.def = def; 17 | this.title = title; 18 | this.bibinfo = bibinfo; 19 | this.label = label; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SideQuote.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | public class SideQuote extends OutputModelObject { 6 | @ModelElement 7 | public TextBlock quote; 8 | 9 | @ModelElement 10 | public TextBlock author; 11 | 12 | public String label; 13 | 14 | public EntityDef def; 15 | 16 | public SideQuote(EntityDef def, String label, TextBlock quote, TextBlock author) { 17 | this.def = def; 18 | this.label = label; 19 | this.quote = quote; 20 | this.author = author; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SideQuoteDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | public class SideQuoteDef extends EntityDef { 7 | public String quote; 8 | public String author; 9 | 10 | public SideQuoteDef(int index, Token startToken, String quote, String author) { 11 | super(index, startToken); 12 | this.quote = Translator.stripCurlies(quote); 13 | this.author = Translator.stripCurlies(author); 14 | } 15 | 16 | public boolean isSideItem() { return true; } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/CitationDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class CitationDef extends EntityDef { 6 | public String title; 7 | public String author; 8 | 9 | public CitationDef(int index, BookishParser.AttrsContext attrsCtx) { 10 | super(index, attrsCtx.attributes); 11 | title = attrsCtx.attributes.get("title"); 12 | author = attrsCtx.attributes.get("author"); 13 | } 14 | 15 | public boolean isGloballyVisible() { return true; } 16 | public boolean isSideItem() { return true; } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/BlockImage.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class BlockImage extends Image { 9 | public BlockImage(Translator translator, String src, String alt) { 10 | super( 11 | translator, 12 | new HashMap<>() 13 | {{ 14 | put("src", src); 15 | put("alt", alt); 16 | }} 17 | ); 18 | } 19 | 20 | public BlockImage(Translator translator, Map attrs) { 21 | super(translator, attrs); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/BlockImage.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class BlockImage extends Image { 9 | public BlockImage(Translator translator, String src, String alt) { 10 | super( 11 | translator, 12 | new HashMap() 13 | {{ 14 | put("src", src); 15 | put("alt", alt); 16 | }} 17 | ); 18 | } 19 | 20 | public BlockImage(Translator translator, Map attrs) { 21 | super(translator, attrs); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/PyFig.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | import java.util.Map; 7 | 8 | public class PyFig extends PyDo { 9 | public PyFig(Translator translator, ExecutableCodeDef codeDef, String stdout, String stderr, Map args) { 10 | super(codeDef, stdout, stderr, args); 11 | String width = args.get("width"); 12 | width = translator.processImageWidth(width); 13 | if ( width==null ) { 14 | width = "100"; 15 | } 16 | args.put("width", width); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/PyFigDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class PyFigDef extends ExecutableCodeDef { 6 | public String generatedFilenameNoSuffix; // minus suffix; could be .svg, .png, or .pdf 7 | 8 | public PyFigDef(BookishParser.PyfigContext tree, 9 | String inputFilename, 10 | int index, 11 | BookishParser.AttrsContext attrsCtx, 12 | String code) 13 | { 14 | super(tree, inputFilename, index, attrsCtx, code); 15 | this.isOutputVisible = false; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/PyFig.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | import java.util.Map; 7 | 8 | public class PyFig extends PyDo { 9 | public PyFig(Translator translator, ExecutableCodeDef codeDef, String stdout, String stderr, Map args) { 10 | super(codeDef, stdout, stderr, args); 11 | String width = args.get("width"); 12 | width = translator.processImageWidth(width); 13 | if ( width==null ) { 14 | width = "100"; 15 | } 16 | args.put("width", width); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/EntityWithScope.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public abstract class EntityWithScope extends EntityDef { 6 | public String title; 7 | 8 | public EntityWithScope(int index, 9 | BookishParser.AttrsContext attrsCtx, 10 | EntityWithScope enclosingScope) 11 | { 12 | super(index, attrsCtx.attributes); 13 | this.enclosingScope = enclosingScope; 14 | this.title = attrsCtx.attributes.get("title"); 15 | if ( label==null ) { 16 | label = "sec:"+getEntityID(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/PyEval.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | import java.util.Map; 6 | 7 | public class PyEval extends PyDo { 8 | public String dataType; 9 | public String displayData; 10 | 11 | public PyEval(ExecutableCodeDef codeDef, 12 | String stdout, 13 | String stderr, 14 | Map args, 15 | String dataType, 16 | String displayData) 17 | { 18 | super(codeDef, stdout, stderr, args); 19 | this.dataType = dataType; 20 | this.displayData = displayData; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/PyEval.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | import java.util.Map; 6 | 7 | public class PyEval extends PyDo { 8 | public String dataType; 9 | public String displayData; 10 | 11 | public PyEval(ExecutableCodeDef codeDef, 12 | String stdout, 13 | String stderr, 14 | Map args, 15 | String dataType, 16 | String displayData) 17 | { 18 | super(codeDef, stdout, stderr, args); 19 | this.dataType = dataType; 20 | this.displayData = displayData; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/CitationDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import us.parr.bookish.translate.Translator; 5 | 6 | public class CitationDef extends EntityDef { 7 | public String title; 8 | 9 | public String bibinfo; 10 | 11 | public CitationDef(int index, Token startToken, String title, String bibinfo) { 12 | super(index,startToken); 13 | this.title = Translator.stripCurlies(title); 14 | this.bibinfo = Translator.stripCurlies(bibinfo); 15 | } 16 | 17 | public boolean isGloballyVisible() { return true; } 18 | public boolean isSideItem() { return true; } 19 | } 20 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Join.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Join extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public Join(List elements) { 11 | this.elements = elements; 12 | } 13 | public Join(List elements, 14 | List others) 15 | { 16 | this.elements = elements; 17 | this.elements.addAll(others); 18 | } 19 | 20 | public Join(OutputModelObject... elements) { 21 | this.elements = Arrays.asList(elements); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/InlinePyEvalDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.Token; 5 | 6 | public class InlinePyEvalDef extends ExecutableCodeDef { 7 | public InlinePyEvalDef(ParserRuleContext tree, 8 | String inputFilename, 9 | int index, 10 | Token startOrRefToken, 11 | String code) { 12 | super(tree, inputFilename, index, startOrRefToken, null, code); 13 | this.isCodeVisible = false; 14 | displayExpr = code; 15 | this.code = null; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Join.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Join extends OutputModelObject { 7 | @ModelElement 8 | public List elements; 9 | 10 | public Join(List elements) { 11 | this.elements = elements; 12 | } 13 | public Join(List elements, 14 | List others) 15 | { 16 | this.elements = elements; 17 | this.elements.addAll(others); 18 | } 19 | 20 | public Join(OutputModelObject... elements) { 21 | this.elements = Arrays.asList(elements); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Article.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | /** Unused */ 8 | public class Article extends Chapter { 9 | public Article(EntityDef def, 10 | String title, 11 | String anchor, 12 | Author author, 13 | PreAbstract preabstract, 14 | Abstract abstract_, 15 | List elements, 16 | List sections) 17 | { 18 | super(def, title, anchor, author, preabstract, abstract_, elements, sections); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SideFigure.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.Map; 6 | 7 | public class SideFigure extends OutputModelObject { 8 | @ModelElement 9 | public TextBlock code; 10 | 11 | public String caption; 12 | 13 | public String label; 14 | public EntityDef def; 15 | 16 | public Map attributes; 17 | 18 | public SideFigure(EntityDef def, String label, TextBlock code) { 19 | this.def = def; 20 | this.label = label; 21 | this.code = code; 22 | this.attributes = def.attributes; 23 | this.caption = attributes.get("caption"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/InlinePyEvalDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import us.parr.bookish.parse.BookishParser; 5 | 6 | public class InlinePyEvalDef extends ExecutableCodeDef { 7 | public InlinePyEvalDef(ParserRuleContext tree, 8 | String inputFilename, 9 | int index, 10 | BookishParser.AttrsContext attrsCtx, 11 | String code) 12 | { 13 | super(tree, inputFilename, index, attrsCtx, code); 14 | this.isCodeVisible = false; 15 | displayExpr = code; 16 | this.code = null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/PyFigDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | import java.util.Map; 6 | 7 | public class PyFigDef extends ExecutableCodeDef { 8 | public String generatedFilenameNoSuffix; // minus suffix; could be .svg, .png, or .pdf 9 | 10 | public PyFigDef(BookishParser.PyfigContext tree, 11 | String inputFilename, 12 | int index, 13 | Map attributes, 14 | String code) 15 | { 16 | super(tree, inputFilename, index, tree.getStart(), attributes, code); 17 | this.isOutputVisible = false; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SubSection.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public class SubSection extends Section { 8 | public SubSection(EntityDef def, 9 | String title, 10 | String anchor, 11 | List elements, 12 | List subsections) 13 | { 14 | super(def, title, anchor, elements, subsections); 15 | } 16 | 17 | @Override 18 | public String getAnchor() { 19 | if ( anchor!=null ) return anchor; 20 | return "sec"+parent.sectionNumber+"."+sectionNumber; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ContainerWithTitle.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public abstract class ContainerWithTitle extends OutputModelObject { 8 | @ModelElement 9 | public OutputModelObject content; 10 | @ModelElement 11 | public List subcontainers; 12 | 13 | public String title; 14 | 15 | public EntityDef def; 16 | 17 | public ContainerWithTitle(EntityDef def, String title, OutputModelObject content) { 18 | this.def = def; 19 | if ( def!=null ) { 20 | def.model = this; 21 | } 22 | this.content = content; 23 | this.title = title; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/SubSubSection.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public class SubSubSection extends SubSection { 8 | public SubSubSection(EntityDef def, 9 | String title, 10 | String anchor, 11 | List elements) 12 | { 13 | super(def, title, anchor, elements, null); 14 | } 15 | 16 | @Override 17 | public String getAnchor() { 18 | if ( anchor!=null ) return anchor; 19 | return "sec"+ 20 | parent.parent.sectionNumber+"."+ 21 | parent.sectionNumber+"."+ 22 | sectionNumber; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/TableHeaderItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class TableHeaderItem extends TableItem { 7 | public Integer widthPercentage = null; 8 | public Map attrs; 9 | 10 | public TableHeaderItem(List contents, 11 | Map attrs) 12 | { 13 | super(contents); 14 | this.attrs = attrs; 15 | if ( attrs.containsKey("width") ) { 16 | String value = attrs.get("width"); 17 | if ( value.endsWith("%") ) { 18 | widthPercentage = Integer.parseInt(value.substring(0,value.length()-1)); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/EntityWithScope.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | 5 | public abstract class EntityWithScope extends EntityDef { 6 | public EntityWithScope enclosingScope; 7 | 8 | public EntityWithScope(int index, Token startToken, EntityWithScope enclosingScope) { 9 | super(index, startToken); 10 | this.enclosingScope = enclosingScope; 11 | } 12 | 13 | /** Return string indicating which section or chapter number */ 14 | public String getContainerNumber() { 15 | if ( enclosingScope==null ) { 16 | return String.valueOf(index); 17 | } 18 | return enclosingScope.getContainerNumber()+'.'+String.valueOf(index); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/PyEvalDataFrame.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | import us.parr.bookish.util.DataTable; 5 | 6 | import java.util.Map; 7 | 8 | public class PyEvalDataFrame extends PyEval { 9 | public DataTable dataTable; 10 | 11 | public PyEvalDataFrame(ExecutableCodeDef codeDef, 12 | String stdout, 13 | String stderr, 14 | Map args, 15 | String dataType, 16 | DataTable dataTable) 17 | { 18 | super(codeDef, stdout, stderr, args, dataType, null); 19 | this.dataTable = dataTable; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/PyEvalDataFrame.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | import us.parr.bookish.util.DataTable; 5 | 6 | import java.util.Map; 7 | 8 | public class PyEvalDataFrame extends PyEval { 9 | public DataTable dataTable; 10 | 11 | public PyEvalDataFrame(ExecutableCodeDef codeDef, 12 | String stdout, 13 | String stderr, 14 | Map args, 15 | String dataType, 16 | DataTable dataTable) 17 | { 18 | super(codeDef, stdout, stderr, args, dataType, null); 19 | this.dataTable = dataTable; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Paragraph.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Paragraph extends OutputModelObject { 9 | @ModelElement 10 | public OutputModelObject content; 11 | 12 | public List entitiesRefd; 13 | public List entitiesOnRight = new ArrayList<>(); 14 | 15 | public Paragraph(OutputModelObject content, List entitiesRefd) { 16 | this.content = content; 17 | this.entitiesRefd = entitiesRefd; 18 | for (EntityDef def : entitiesRefd) { 19 | if ( def.isSideItem() ) { 20 | entitiesOnRight.add(def); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/TableHeaderItem.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class TableHeaderItem extends TableItem { 7 | public Integer widthPercentage = null; 8 | public Map attributes; 9 | 10 | public TableHeaderItem(List contents, 11 | Map attributes) 12 | { 13 | super(contents); 14 | this.attributes = attributes; 15 | if ( attributes.containsKey("width") ) { 16 | String value = attributes.get("width"); 17 | if ( value.endsWith("%") ) { 18 | widthPercentage = Integer.parseInt(value.substring(0,value.length()-1)); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Paragraph.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Paragraph extends OutputModelObject { 9 | @ModelElement 10 | public List elements; 11 | 12 | public List entitiesRefd; 13 | public List entitiesOnRight = new ArrayList<>(); 14 | 15 | public Paragraph(List elements, List entitiesRefd) { 16 | this.elements = elements; 17 | this.entitiesRefd = entitiesRefd; 18 | for (EntityDef def : entitiesRefd) { 19 | if ( def.isSideItem() ) { 20 | entitiesOnRight.add(def); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/ref/Figure.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model.ref; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | import us.parr.bookish.model.ModelElement; 5 | import us.parr.bookish.model.OutputModelObject; 6 | 7 | import java.util.Map; 8 | 9 | public class Figure extends OutputModelObject { 10 | @ModelElement 11 | public OutputModelObject code; 12 | 13 | public String caption; 14 | 15 | public String label; 16 | public EntityDef def; 17 | 18 | public Map attributes; 19 | 20 | public Figure(EntityDef def, String label, OutputModelObject code) { 21 | this.def = def; 22 | this.label = label; 23 | this.code = code; 24 | this.attributes = def.attributes; 25 | this.caption = attributes.get("caption"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/BookFrontMatterFile.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | import us.parr.bookish.semantics.Book; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class BookFrontMatterFile extends OutputModelObject { 11 | public Book book; 12 | 13 | public Map attributes; 14 | 15 | /** The chapter model objects (not templates) */ 16 | public List chapterDocuments = new ArrayList<>(); 17 | 18 | public BookFrontMatterFile(Book book) { 19 | this.book = book; 20 | BookishParser.BookContext b = book.rootdoc.getTreeAsRoot().book(); 21 | this.attributes = b.attrs().attributes; 22 | } 23 | 24 | public String getTitle() { return book.title; } 25 | } 26 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/InlineEquation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineEquation extends InlineImage { 4 | public String eqn; 5 | public float height, depth; 6 | public int descentPercentage; 7 | public int depthRounded; 8 | public float depthTweaked; 9 | 10 | public InlineEquation(String imageFilename, String eqn, float height, float depth) { 11 | super(imageFilename); 12 | this.eqn = eqn; 13 | this.height = height; 14 | this.depth = depth; 15 | if ( depth < 0.5 ) { 16 | depthTweaked = 0.5f; 17 | } 18 | else if ( depth < 1.3 ) { 19 | depthTweaked = depth;//0.5f; 20 | } 21 | else { 22 | depthTweaked = depth*1.05f; 23 | } 24 | this.descentPercentage = (int)(100*depth/(height+depth)); 25 | depthRounded = Math.round(depth); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/InlineEquation.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | public class InlineEquation extends InlineImage { 4 | public String eqn; 5 | public float height, depth; 6 | public int descentPercentage; 7 | public int depthRounded; 8 | public float depthTweaked; 9 | 10 | public InlineEquation(String imageFilename, String eqn, float height, float depth) { 11 | super(imageFilename); 12 | this.eqn = eqn; 13 | this.height = height; 14 | this.depth = depth; 15 | if ( depth < 0.5 ) { 16 | depthTweaked = 0.5f; 17 | } 18 | else if ( depth < 1.3 ) { 19 | depthTweaked = depth;//0.5f; 20 | } 21 | else { 22 | depthTweaked = depth*1.05f; 23 | } 24 | this.descentPercentage = (int)(100*depth/(height+depth)); 25 | depthRounded = Math.round(depth); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/PyDo.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | import java.util.Map; 6 | 7 | /** Execute some python code. 8 | * Used as base class; not used in templates as output object. 9 | */ 10 | public abstract class PyDo extends OutputModelObject { 11 | public ExecutableCodeDef codeDef; 12 | public String stdout; 13 | public String stderr; 14 | public Map args; 15 | 16 | public PyDo(ExecutableCodeDef codeDef, String stdout, String stderr, Map args) { 17 | this.codeDef = codeDef; 18 | this.args = args; 19 | if ( stdout!=null ) { 20 | this.stdout = stdout.trim().length()>0 ? stdout : null; 21 | } 22 | if ( stderr!=null ) { 23 | this.stderr = stderr.trim().length()>0 ? stderr : null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/us/parr/bookish/semantics/Book.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.semantics; 2 | 3 | import org.stringtemplate.v4.STGroup; 4 | import org.stringtemplate.v4.STGroupFile; 5 | import us.parr.bookish.Tool; 6 | import us.parr.bookish.translate.HTMLEscaper; 7 | import us.parr.bookish.translate.LatexEscaper; 8 | 9 | public class Book extends Artifact { 10 | public Book(Tool tool, String title) { 11 | super(tool, title); 12 | } 13 | 14 | public STGroup loadTemplates() { 15 | String templateFileName = "templates/"+tool.target+"-book.stg"; 16 | STGroup templates = new STGroupFile(templateFileName); 17 | if ( tool.isLatexTarget() ) { 18 | templates.registerRenderer(String.class, new LatexEscaper()); 19 | } 20 | else { 21 | templates.registerRenderer(String.class, new HTMLEscaper()); 22 | } 23 | return templates; 24 | } 25 | } -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/PyDo.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ExecutableCodeDef; 4 | 5 | import java.util.Map; 6 | 7 | /** Execute some python code. 8 | * Used as base class; not used in templates as output object. 9 | */ 10 | public abstract class PyDo extends OutputModelObject { 11 | public ExecutableCodeDef codeDef; 12 | public String stdout; 13 | public String stderr; 14 | public Map args; 15 | 16 | public PyDo(ExecutableCodeDef codeDef, String stdout, String stderr, Map args) { 17 | this.codeDef = codeDef; 18 | this.args = args; 19 | if ( stdout!=null ) { 20 | this.stdout = stdout.trim().length()>0 ? stdout : null; 21 | } 22 | if ( stderr!=null ) { 23 | this.stderr = stderr.trim().length()>0 ? stderr : null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/us/parr/bookish/semantics/Article.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.semantics; 2 | 3 | import org.stringtemplate.v4.STGroup; 4 | import org.stringtemplate.v4.STGroupFile; 5 | import us.parr.bookish.Tool; 6 | import us.parr.bookish.translate.HTMLEscaper; 7 | import us.parr.bookish.translate.LatexEscaper; 8 | 9 | public class Article extends Artifact { 10 | public Article(Tool tool, String title) { 11 | super(tool, title); 12 | } 13 | 14 | public STGroup loadTemplates() { 15 | String templateFileName = "templates/"+tool.target+"-article.stg"; 16 | STGroup templates = new STGroupFile(templateFileName); 17 | if ( tool.isLatexTarget() ) { 18 | templates.registerRenderer(String.class, new LatexEscaper()); 19 | } 20 | else { 21 | templates.registerRenderer(String.class, new HTMLEscaper()); 22 | } 23 | return templates; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/ChapterDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import org.antlr.v4.runtime.misc.Pair; 5 | 6 | import static us.parr.bookish.translate.Translator.splitSectionTitle; 7 | 8 | public class ChapterDef extends EntityWithScope { 9 | public String title; 10 | 11 | public ChapterDef(int chapNumber, Token titleToken, EntityWithScope enclosingScope) { 12 | super(chapNumber, titleToken, enclosingScope); 13 | String title = titleToken.getText(); 14 | title = title.substring(title.indexOf(' ')+1).trim(); 15 | Pair results = splitSectionTitle(title); 16 | this.title = results.a; 17 | this.label = results.b; 18 | if ( label==null ) { 19 | label = "chp:"+getContainerNumber(); 20 | } 21 | } 22 | 23 | public boolean isGloballyVisible() { return true; } 24 | } 25 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/SectionDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import org.antlr.v4.runtime.misc.Pair; 5 | 6 | import static us.parr.bookish.translate.Translator.splitSectionTitle; 7 | 8 | public class SectionDef extends EntityWithScope { 9 | public String title; 10 | 11 | public SectionDef(int secNumber, Token titleToken, EntityWithScope enclosingScope) { 12 | super(secNumber, titleToken, enclosingScope); 13 | String title = titleToken.getText(); 14 | title = title.substring(title.indexOf(' ')+1).trim(); 15 | Pair results = splitSectionTitle(title); 16 | this.title = results.a; 17 | this.label = results.b; 18 | if ( label==null ) { 19 | label = "sec:"+getContainerNumber(); 20 | } 21 | } 22 | 23 | public boolean isGloballyVisible() { return true; } 24 | } 25 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/ContainerWithTitle.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public abstract class ContainerWithTitle extends OutputModelObject { 8 | @ModelElement 9 | public List elements; 10 | @ModelElement 11 | public List subcontainers; 12 | 13 | public ContainerWithTitle parent; // who contains us? 14 | public String title; 15 | public String anchor; 16 | 17 | public EntityDef def; 18 | 19 | public int sectionNumber; 20 | 21 | public ContainerWithTitle(EntityDef def, String title, String anchor, List elements) { 22 | this.def = def; 23 | if ( def!=null ) { 24 | def.model = this; 25 | } 26 | this.elements = elements; 27 | this.title = title; 28 | this.anchor = anchor; 29 | } 30 | 31 | public abstract void connectContainerTree(ContainerWithTitle parent, int n); 32 | } 33 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Section.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | 5 | import java.util.List; 6 | 7 | public class Section extends ContainerWithTitle { 8 | public Section(EntityDef def, 9 | String title, 10 | String anchor, 11 | List elements, 12 | List subsections) 13 | { 14 | super(def, title, anchor, elements); 15 | this.subcontainers = subsections; 16 | } 17 | 18 | public void connectContainerTree(ContainerWithTitle parent, int n) { 19 | this.parent = parent; 20 | sectionNumber = n; 21 | int i = 1; 22 | if ( subcontainers!=null ) { 23 | for (ContainerWithTitle subcontainer : subcontainers) { 24 | subcontainer.connectContainerTree(this, i++); 25 | } 26 | } 27 | } 28 | 29 | public String getAnchor() { 30 | if ( anchor!=null ) return anchor; 31 | return "sec"+sectionNumber; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/parse/XML.g4: -------------------------------------------------------------------------------- 1 | grammar XML; 2 | 3 | @header { 4 | import java.util.Map; 5 | import java.util.HashMap; 6 | import java.util.LinkedHashMap; 7 | import java.util.Arrays; 8 | 9 | import us.parr.lib.ParrtStrings; 10 | import us.parr.lib.ParrtCollections; 11 | import us.parr.lib.ParrtIO; 12 | import us.parr.bookish.model.entity.*; 13 | import static us.parr.bookish.translate.Translator.splitSectionTitle; 14 | } 15 | 16 | 17 | attrs returns [Map attrMap = new LinkedHashMap<>()] 18 | : attr_assignment[$attrMap]* 19 | ; 20 | 21 | attr_assignment[Map attrMap] 22 | : name=XML_ATTR XML_EQ value=(XML_ATTR_VALUE|XML_ATTR|XML_NUM) 23 | { 24 | String v = $value.text; 25 | if ( v.startsWith("\"") ) { 26 | v = ParrtStrings.stripQuotes(v); 27 | } 28 | $attrMap.put($name.text,v); 29 | } 30 | ; 31 | 32 | XML_NUM : [0-9]+ ('.' [0-9]*)? ; 33 | XML_ATTR : [a-zA-Z]+ ; 34 | XML_EQ : '=' ; 35 | XML_ATTR_VALUE : '"' ('\\"'|~'"')* '"' ; 36 | 37 | WS : [ \t\n\r]+ -> skip ; -------------------------------------------------------------------------------- /src/us/parr/bookish/translate/LatexEscaper.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.translate; 2 | 3 | import org.stringtemplate.v4.StringRenderer; 4 | 5 | import java.util.Locale; 6 | 7 | public class LatexEscaper extends StringRenderer { 8 | @Override 9 | public String toString(Object o, String formatString, Locale locale) { 10 | String s = (String)o; 11 | if ( formatString!=null && formatString.equals("url-escape") ) { 12 | s = s.replace("~", "\\textasciitilde{}"); 13 | s = escape(s); 14 | return s; 15 | } 16 | else if ( formatString!=null && formatString.equals("escape") ) { 17 | s = escape(s); 18 | return s; 19 | } 20 | return super.toString(o, formatString, locale); 21 | } 22 | 23 | private String escape(String s) { 24 | s = s.replace("\\", "\\\\"); 25 | s = s.replace("_", "\\_"); 26 | s = s.replace("#", "\\#"); 27 | s = s.replace("&", "\\&"); 28 | s = s.replace("$", "\\$"); 29 | s = s.replace("%", "\\%"); 30 | s = s.replace("<", "\\textless"); 31 | s = s.replace(">", "\\textgreater"); 32 | return s; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/translate/LatexEscaper.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.translate; 2 | 3 | import org.stringtemplate.v4.StringRenderer; 4 | 5 | import java.util.Locale; 6 | 7 | public class LatexEscaper extends StringRenderer { 8 | @Override 9 | public String toString(Object o, String formatString, Locale locale) { 10 | String s = (String)o; 11 | if ( formatString!=null && formatString.equals("url-escape") ) { 12 | s = s.replace("~", "\\textasciitilde{}"); 13 | s = escape(s); 14 | return s; 15 | } 16 | else if ( formatString!=null && formatString.equals("escape") ) { 17 | s = escape(s); 18 | return s; 19 | } 20 | return super.toString(o, formatString, locale); 21 | } 22 | 23 | private String escape(String s) { 24 | s = s.replace("\\", "\\\\"); 25 | s = s.replace("_", "\\_"); 26 | s = s.replace("#", "\\#"); 27 | s = s.replace("&", "\\&"); 28 | s = s.replace("$", "\\$"); 29 | s = s.replace("%", "\\%"); 30 | s = s.replace("<", "\\textless"); 31 | s = s.replace(">", "\\textgreater"); 32 | return s; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Terence Parr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /resources/templates/eqntex.stg: -------------------------------------------------------------------------------- 1 | delimiters "<", ">" 2 | 3 | texdoc(body,fontsize) ::= << 4 | \documentclass[fontsize=pt]{scrlttr2} 5 | \usepackage{graphicx} 6 | \usepackage{epstopdf} 7 | \usepackage{amsmath} 8 | \usepackage{amssymb} 9 | \usepackage{amsfonts} 10 | \usepackage[noline, boxed, titlenotnumbered, linesnumberedhidden]{algorithm2e} 11 | 12 | \DeclareSymbolFont{operators} {OT1}{ztmcm}{m}{n} 13 | \DeclareSymbolFont{letters} {OML}{ztmcm}{m}{it} 14 | \DeclareSymbolFont{symbols} {OMS}{ztmcm}{m}{n} 15 | \DeclareSymbolFont{largesymbols}{OMX}{ztmcm}{m}{n} 16 | \DeclareSymbolFont{bold} {OT1}{ptm}{bx}{n} 17 | \DeclareSymbolFont{italic} {OT1}{ptm}{m}{it} 18 | \renewcommand\vec{\mathbf} 19 | \begin{document} 20 | \thispagestyle{empty} 21 | 22 | \setbox0=\vbox{\} 23 | \typeout{// bookish metrics: \the\ht0, \the\dp0\} 24 | \end{document} 25 | >> 26 | 27 | eqntex(text,fontsize) ::= << 28 | $}, fontsize=fontsize)> 29 | >> 30 | 31 | blockeqntex(text,fontsize) ::= << 32 | \]}, fontsize=fontsize)> 33 | >> 34 | 35 | blocktex(text,fontsize) ::= << 36 | }, fontsize=fontsize)> 37 | >> -------------------------------------------------------------------------------- /src/us/parr/bookish/parse/ChapDocInfo.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.parse; 2 | 3 | import org.antlr.v4.runtime.Parser; 4 | import us.parr.bookish.entity.EntityDef; 5 | import us.parr.bookish.entity.ExecutableCodeDef; 6 | import us.parr.bookish.semantics.Artifact; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** A parsed input file. Track the parse tree and the parser that created it. 12 | * Also track semantic information such as the definitions within this document. 13 | * Every document exists within an artifact. 14 | */ 15 | public class ChapDocInfo extends DocInfo { 16 | public int docNumber; // from 1 17 | 18 | public List codeBlocks = new ArrayList<>(); 19 | 20 | public ChapDocInfo(Artifact artifact, Parser parser, BookishParser.ChapterContext tree) { 21 | super(artifact, parser, tree); 22 | this.parser = parser; 23 | this.tree = tree; 24 | } 25 | 26 | public EntityDef getEntity(String label) { 27 | EntityDef d = entities.get(label); 28 | if ( d!=null ) return d; 29 | return artifact.getEntity(label); 30 | } 31 | 32 | public BookishParser.ChapterContext getTreeAsChapter() { return (BookishParser.ChapterContext)tree; } 33 | } 34 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Chapter.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.ChapterDef; 4 | import us.parr.bookish.parse.DocInfo; 5 | import us.parr.bookish.semantics.Artifact; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class Chapter extends ContainerWithTitle { 11 | @ModelElement 12 | public PreAbstract preabstract; 13 | @ModelElement 14 | public Abstract abstract_; 15 | 16 | public Artifact artifact; // book or article 17 | 18 | public DocInfo docInfo; // specific document 19 | 20 | public String copyright; 21 | 22 | public String generatedFilename; 23 | 24 | public Map attributes; 25 | 26 | public Chapter(Artifact artifact, 27 | DocInfo docInfo, 28 | ChapterDef def, 29 | PreAbstract preabstract, 30 | Abstract abstract_, 31 | OutputModelObject content, 32 | List sections) 33 | { 34 | super(def, def.title, content); 35 | this.docInfo = docInfo; 36 | this.artifact = artifact; 37 | this.abstract_ = abstract_; 38 | this.preabstract = preabstract; 39 | this.subcontainers = sections; 40 | this.attributes = def.attributes; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/us/parr/bookish/parse/RootDocInfo.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.parse; 2 | 3 | import org.antlr.v4.runtime.Parser; 4 | import org.antlr.v4.runtime.ParserRuleContext; 5 | import org.antlr.v4.runtime.tree.ParseTree; 6 | import us.parr.bookish.semantics.Artifact; 7 | 8 | import java.util.Map; 9 | 10 | public class RootDocInfo extends DocInfo { 11 | public Map attributes; // book or article attributes 12 | 13 | public RootDocInfo(Artifact artifact, Parser parser, ParserRuleContext tree) { 14 | super(artifact, parser, tree); 15 | this.parser = parser; 16 | this.tree = tree; 17 | ParseTree rootTag = tree.getChild(0); 18 | if ( rootTag instanceof BookishParser.BookContext ) { 19 | attributes = ((BookishParser.BookContext)rootTag).attrs().attributes; 20 | } 21 | else { 22 | if ( ((BookishParser.ArticleContext)rootTag).attrs()!=null ) { 23 | attributes = ((BookishParser.ArticleContext) rootTag).attrs().attributes; 24 | } 25 | } 26 | } 27 | 28 | public String getGeneratedFilename(String target) { 29 | String outFilename = "index.html"; 30 | if ( target.equals("latex") ) { 31 | outFilename = getSourceBaseName()+".tex"; 32 | } 33 | return outFilename; 34 | } 35 | 36 | public BookishParser.RootdocumentContext getTreeAsRoot() { return (BookishParser.RootdocumentContext)tree; } 37 | } 38 | -------------------------------------------------------------------------------- /src/us/parr/bookish/semantics/BookishBaseListener.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.semantics; 2 | 3 | import us.parr.bookish.entity.ChapterDef; 4 | import us.parr.bookish.entity.SectionDef; 5 | import us.parr.bookish.parse.BookishParser; 6 | import us.parr.bookish.parse.BookishParserBaseListener; 7 | 8 | /** This is the base class that tracks the current chapter and current section 9 | * for listeners that occur after the {@link DefEntitiesListener}. It 10 | * extracts the current pointers from the parse tree that were annotated 11 | * during entity definition phase. 12 | */ 13 | public class BookishBaseListener extends BookishParserBaseListener { 14 | /** Points at the current chapter */ 15 | public ChapterDef currentChap; 16 | 17 | /** Points at either a section, subsection, or subsection */ 18 | public SectionDef currentSecPtr; 19 | 20 | @Override 21 | public void enterChapter(BookishParser.ChapterContext ctx) { 22 | currentChap = ctx.def; 23 | } 24 | 25 | @Override 26 | public void enterSection(BookishParser.SectionContext ctx) { 27 | currentSecPtr = ctx.def; 28 | } 29 | 30 | @Override 31 | public void enterSubsection(BookishParser.SubsectionContext ctx) { 32 | currentSecPtr = ctx.def; 33 | } 34 | 35 | @Override 36 | public void enterSubsubsection(BookishParser.SubsubsectionContext ctx) { 37 | currentSecPtr = ctx.def; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/ExecutableCodeDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.Token; 5 | 6 | import java.util.Map; 7 | 8 | import static us.parr.lib.ParrtStrings.expandTabs; 9 | 10 | public abstract class ExecutableCodeDef extends EntityDef { 11 | public ParserRuleContext tree; 12 | 13 | public String code; 14 | public String displayExpr; 15 | public String inputFilename; 16 | public SectionDef enclosingSection; 17 | public ChapterDef enclosingChapter; 18 | 19 | public boolean isCodeVisible = true; 20 | public boolean isOutputVisible = true; 21 | 22 | public Map attributes; 23 | 24 | public ExecutableCodeDef(ParserRuleContext tree, 25 | String inputFilename, 26 | int index, 27 | Token startOrRefToken, 28 | Map attributes, 29 | String code) 30 | { 31 | super(index, startOrRefToken); 32 | this.tree = tree; 33 | this.inputFilename = inputFilename; 34 | this.code = expandTabs(code, 4); 35 | this.attributes = attributes; 36 | if ( attributes!=null ) { 37 | this.label = attributes.get("label"); 38 | if ( attributes.containsKey("hide") ) { 39 | isCodeVisible = !attributes.get("hide").equals("true"); 40 | } 41 | if ( attributes.containsKey("output") ) { 42 | displayExpr = attributes.get("output"); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Document.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.entity.EntityDef; 4 | import us.parr.bookish.parse.BookishParser; 5 | 6 | import java.util.HashMap; 7 | import java.util.HashSet; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | public class Document extends OutputModelObject { 12 | @ModelElement 13 | public Chapter chapter; 14 | 15 | public Book book; // parent 16 | public String markdownFilename; 17 | public String generatedFilename; 18 | 19 | /** All the labeled entities defined in this document */ 20 | public Map entities = new HashMap<>(); 21 | 22 | /** Track which non-globally visible figures/notes we have already displayed; 23 | * don't show them more than once. 24 | */ 25 | public Set entitiesRendered = new HashSet<>(); 26 | 27 | public BookishParser.DocumentContext tree; 28 | 29 | public Document(BookishParser.DocumentContext tree) { 30 | this.tree = tree; 31 | } 32 | 33 | /** Look in this doc scope first, which has locally-visible symbols only. 34 | * If not found, look in global scope, which has chap,sec,figures,citations. 35 | * Symbols initial defined in this scope during the parse then moved 36 | * to global scope in Book. 37 | */ 38 | public EntityDef getEntity(String label) { 39 | EntityDef def = entities.get(label); 40 | if ( def==null ) { 41 | def = book.getEntity(label); 42 | } 43 | return def; 44 | } 45 | 46 | public String getTitle() { return book.title; } 47 | } 48 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Book.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.Tool; 4 | import us.parr.bookish.entity.EntityDef; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Set; 12 | 13 | public class Book extends OutputModelObject { 14 | public Tool tool; 15 | public String author; 16 | public String title; 17 | 18 | public List filenames = new ArrayList<>(); 19 | 20 | /** The chapter model objects (not templates) */ 21 | public List chapterDocuments = new ArrayList<>(); 22 | 23 | /** Global labeled entities such as chap,sec,figures,citations. 24 | * Collected from all input markdown files. Does not include 25 | * locally-scoped labels like sidenote labels. 26 | */ 27 | public Map entities = new HashMap<>(); 28 | 29 | /** Track which figures we have already displayed; don't show them more than once. */ 30 | public Set entitiesRendered = new HashSet<>(); 31 | 32 | public int chapCounter = 1; 33 | 34 | public String type; // book, article, etc... 35 | 36 | public Book(Tool tool, String title, String author) { 37 | this.tool = tool; 38 | this.author = author; 39 | this.title = title; 40 | } 41 | 42 | /** Add doc wrapper for a chapter */ 43 | public void addChapterDocument(Document doc) { 44 | doc.book = this; 45 | chapterDocuments.add(doc); 46 | } 47 | 48 | public EntityDef getEntity(String label) { 49 | return entities.get(label); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/entity/EntityDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import org.stringtemplate.v4.ST; 5 | import us.parr.bookish.model.OutputModelObject; 6 | 7 | import java.util.Objects; 8 | 9 | import static us.parr.lib.ParrtStrings.stripQuotes; 10 | 11 | public class EntityDef { 12 | public String label; // optional label 13 | public Token startToken; 14 | 15 | /** indexed from 1; fig, citation, sidenote number. 16 | * Does not track chp/sec numbers. Those are done via 17 | * ContainerWithTitle.connectContainerTree(). 18 | */ 19 | public int index; 20 | 21 | public OutputModelObject model; 22 | public ST template; 23 | 24 | public EntityDef(int index, Token refOrStartToken) { 25 | this.index = index; 26 | this.startToken = refOrStartToken; 27 | if ( startToken!=null && startToken.getText().startsWith("[") ) { 28 | this.label = stripQuotes(refOrStartToken.getText()); 29 | } 30 | } 31 | 32 | public boolean isGloballyVisible() { return false; } 33 | 34 | public Token getStartToken() { return startToken; } 35 | 36 | public boolean isSideItem() { return false; } 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if ( this==o ) return true; 41 | if ( !(o instanceof EntityDef) ) return false; 42 | EntityDef entityDef = (EntityDef) o; 43 | return Objects.equals(label, entityDef.label); 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | return Objects.hash(label); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return '<'+label+":"+this.getClass().getSimpleName()+'>'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/model/Image.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | import us.parr.lib.ParrtIO; 5 | 6 | import java.util.HashSet; 7 | import java.util.Map; 8 | import java.util.Set; 9 | 10 | public class Image extends OutputModelObject { 11 | public static final Set supportedSingleFormats = new HashSet() {{ 12 | add("jpg"); 13 | add("png"); 14 | }}; 15 | 16 | public Translator translator; 17 | public Map attrs; 18 | 19 | public Image(Translator translator, Map attrs) { 20 | this.translator = translator; 21 | this.attrs = attrs; 22 | if ( attrs.containsKey("src") ) { 23 | String src = attrs.get("src"); 24 | String ext = ParrtIO.fileExtension(src); 25 | if ( ext!=null ) { 26 | if ( !supportedSingleFormats.contains(ext) ) { 27 | // then strip it and add appropriate ext for translation target 28 | if ( translator.isHTMLTarget() ) { 29 | src = ParrtIO.replaceFileExtension(src, ".svg"); 30 | } 31 | else if ( translator.isLatexTarget() ) { 32 | src = ParrtIO.replaceFileExtension(src, ".pdf"); 33 | } 34 | } 35 | } 36 | else { 37 | if ( translator.isHTMLTarget() ) { 38 | src = src + ".svg"; 39 | } 40 | else if ( translator.isLatexTarget() ) { 41 | src = src + ".pdf"; 42 | } 43 | } 44 | attrs.put("src", src); 45 | } 46 | else { 47 | System.err.println("No src attribute on IMG tag"); 48 | } 49 | String width = attrs.get("width"); 50 | width = translator.processImageWidth(width); 51 | attrs.put("width", width); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/ExecutableCodeDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import us.parr.bookish.parse.BookishParser; 5 | 6 | import static us.parr.lib.ParrtStrings.expandTabs; 7 | 8 | public abstract class ExecutableCodeDef extends EntityDef { 9 | public static final String DEFAULT_CODE_LABEL = "snippets"; 10 | 11 | public ParserRuleContext tree; 12 | 13 | public String code; 14 | public String displayExpr; 15 | public String inputFilename; 16 | public SectionDef enclosingSection; 17 | public ChapterDef enclosingChapter; 18 | 19 | public boolean isCodeVisible = true; 20 | public boolean isOutputVisible = true; 21 | public boolean isEnabled = true; 22 | 23 | public ExecutableCodeDef(ParserRuleContext tree, 24 | String inputFilename, 25 | int index, 26 | BookishParser.AttrsContext attrsCtx, 27 | String code) 28 | { 29 | super(index, attrsCtx!=null ? attrsCtx.attributes : null); 30 | this.tree = tree; 31 | this.inputFilename = inputFilename; 32 | this.code = expandTabs(code, 4); 33 | if ( attrsCtx!=null ) { 34 | if ( attrsCtx.attributes.containsKey("hide") ) { 35 | isCodeVisible = !attrsCtx.attributes.get("hide").equals("true"); 36 | } 37 | if ( attrsCtx.attributes.containsKey("output") ) { 38 | displayExpr = attrsCtx.attributes.get("output"); 39 | } 40 | if ( attrsCtx.attributes.containsKey("disable") ) { 41 | isEnabled = !attrsCtx.attributes.get("disable").equals("true"); 42 | } 43 | } 44 | if ( label==null ) { 45 | label = DEFAULT_CODE_LABEL; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/us/parr/bookish/model/Image.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.model; 2 | 3 | import us.parr.bookish.translate.Translator; 4 | import us.parr.lib.ParrtIO; 5 | 6 | import java.util.HashSet; 7 | import java.util.Map; 8 | import java.util.Set; 9 | 10 | public class Image extends OutputModelObject { 11 | public static final Set supportedSingleFormats = new HashSet<>() {{ 12 | add("jpg"); 13 | add("gif"); 14 | add("png"); 15 | }}; 16 | 17 | public Translator translator; 18 | public Map attributes; 19 | 20 | public Image(Translator translator, Map attributes) { 21 | this.translator = translator; 22 | this.attributes = attributes; 23 | if ( attributes.containsKey("src") ) { 24 | String src = attributes.get("src"); 25 | String ext = ParrtIO.fileExtension(src); 26 | if ( ext!=null ) { 27 | if ( !supportedSingleFormats.contains(ext) ) { 28 | // then strip it and add appropriate ext for translation target 29 | if ( translator.tool.isHTMLTarget() ) { 30 | src = ParrtIO.replaceFileExtension(src, ".svg"); 31 | } 32 | else if ( translator.tool.isLatexTarget() ) { 33 | src = ParrtIO.replaceFileExtension(src, ".pdf"); 34 | } 35 | } 36 | } 37 | else { 38 | if ( translator.tool.isHTMLTarget() ) { 39 | src = src + ".svg"; 40 | } 41 | else if ( translator.tool.isLatexTarget() ) { 42 | src = src + ".pdf"; 43 | } 44 | } 45 | attributes.put("src", src); 46 | } 47 | else { 48 | System.err.println("No src attribute on IMG tag"); 49 | } 50 | String width = attributes.get("width"); 51 | width = translator.processImageWidth(width); 52 | attributes.put("width", width); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/us/parr/bookish/parse/DocInfo.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.parse; 2 | 3 | import org.antlr.v4.runtime.Parser; 4 | import org.antlr.v4.runtime.ParserRuleContext; 5 | import us.parr.bookish.entity.EntityDef; 6 | import us.parr.bookish.semantics.Artifact; 7 | import us.parr.lib.ParrtIO; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class DocInfo { 13 | public Artifact artifact; 14 | public Parser parser; 15 | public ParserRuleContext tree; 16 | 17 | /** For root doc, these are global labeled entities such as 18 | * chap,sec,figures,citations. Collected from all input chap files. 19 | * Does not include locally-scoped labels like sidenote labels. 20 | * Those are stored in same field but for {@link ChapDocInfo} subclass. 21 | */ 22 | public Map entities = new HashMap<>(); 23 | 24 | public DocInfo(Artifact artifact, Parser parser, ParserRuleContext tree) { 25 | this.artifact = artifact; 26 | this.parser = parser; 27 | this.tree = tree; 28 | } 29 | 30 | public String getGeneratedFilename(String target) { 31 | String outFilename = getSourceBaseName()+".html"; 32 | if ( target.equals("latex") ) { 33 | outFilename = getSourceBaseName()+".tex"; 34 | } 35 | return outFilename; 36 | } 37 | 38 | public String getSourceBaseName() { 39 | return ParrtIO.stripFileExtension(getSourceName()); 40 | } 41 | 42 | public String getSourcePathName() { 43 | return parser.getInputStream().getSourceName(); 44 | } 45 | 46 | public String getSourceName() { 47 | return ParrtIO.basename(parser.getInputStream().getSourceName()); 48 | } 49 | 50 | public EntityDef getEntity(String label) { 51 | return entities.get(label); 52 | } 53 | 54 | public void defEntity(String label, EntityDef d) { 55 | entities.put(label, d); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/us/parr/bookish/semantics/ArtifactListener.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.semantics; 2 | 3 | import us.parr.bookish.parse.BookishParser; 4 | 5 | public class ArtifactListener extends BookishBaseListener { 6 | public Artifact artifact; 7 | 8 | public ArtifactListener(Artifact artifact) { 9 | this.artifact = artifact; 10 | } 11 | 12 | @Override 13 | public void enterCopyright(BookishParser.CopyrightContext ctx) { 14 | String location = artifact.rootdoc.getSourceName()+" "+ 15 | ctx.start.getLine()+":"+ 16 | ctx.start.getCharPositionInLine(); 17 | artifact.copyright = artifact.tool.translateString(artifact.rootdoc, ctx.content().getText(), location); 18 | } 19 | 20 | @Override 21 | public void enterAbstract_(BookishParser.Abstract_Context ctx) { 22 | String location = artifact.rootdoc.getSourceName()+" "+ 23 | ctx.start.getLine()+":"+ 24 | ctx.start.getCharPositionInLine(); 25 | artifact.abstract_ = artifact.tool.translateString(artifact.rootdoc, ctx.content().getText(), location); 26 | } 27 | 28 | @Override 29 | public void enterNotebook_support(BookishParser.Notebook_supportContext ctx) { 30 | artifact.notebookResources.add(ctx.attrs().attributes.get("file") ); 31 | } 32 | 33 | @Override 34 | public void enterData(BookishParser.DataContext ctx) { 35 | artifact.dataDir = ctx.attrs().attributes.get("dir"); 36 | } 37 | 38 | @Override 39 | public void enterDataCopy(BookishParser.DataCopyContext ctx) { 40 | artifact.dataFilesToCopy.add( ctx.attrs().attributes.get("file") ); 41 | } 42 | 43 | @Override 44 | public void enterCss(BookishParser.CssContext ctx) { 45 | artifact.cssFile = ctx.attrs().attributes.get("file"); 46 | } 47 | 48 | @Override 49 | public void enterMetadata(BookishParser.MetadataContext ctx) { 50 | artifact.metadata = ctx.attrs().attributes; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/us/parr/bookish/util/DataTable.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.util; 2 | 3 | import org.apache.commons.csv.CSVFormat; 4 | import org.apache.commons.csv.CSVParser; 5 | import org.apache.commons.csv.CSVRecord; 6 | import org.apache.commons.lang3.math.NumberUtils; 7 | import org.apache.commons.math3.util.Precision; 8 | 9 | import java.io.Reader; 10 | import java.io.StringReader; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Set; 14 | 15 | import static us.parr.lib.ParrtStrings.abbrevString; 16 | 17 | public class DataTable { 18 | public List colNames = new ArrayList<>(); 19 | public List> rows = new ArrayList<>(); 20 | public boolean firstColIsIndex; 21 | 22 | public DataTable(String csv) {//, int firstDataRow) { 23 | parseCSV(csv); 24 | } 25 | 26 | public void parseCSV(String csv) { 27 | try { 28 | Reader in = new StringReader(csv); 29 | CSVFormat format = CSVFormat.EXCEL.withHeader(); 30 | CSVParser parser = format.parse(in); 31 | Set colNames = parser.getHeaderMap().keySet(); 32 | this.colNames.addAll(colNames); 33 | this.firstColIsIndex = true; 34 | for (CSVRecord record : parser) { 35 | List row = new ArrayList<>(); 36 | for (int i = 0; i elements, 22 | List sections) 23 | { 24 | super(def, title, anchor, elements); 25 | this.author = author; 26 | this.abstract_ = abstract_; 27 | this.preabstract = preabstract; 28 | this.subcontainers = sections; 29 | } 30 | 31 | @Override 32 | public void connectContainerTree(ContainerWithTitle parent, int n) { 33 | int i = 1; 34 | if ( subcontainers!=null ) { 35 | for (ContainerWithTitle sec : subcontainers) { 36 | sec.connectContainerTree(this, i); 37 | i++; 38 | } 39 | } 40 | } 41 | 42 | public void connectContainerTree() { 43 | connectContainerTree(null,0); 44 | } 45 | 46 | /* 47 | public OutputModelObject createTOCModel() { 48 | if ( sections!=null ) { 49 | List seclist = new ArrayList<>(); 50 | for (Section sec : sections) { 51 | System.out.println(sec.getAnchor()); 52 | seclist.add(new ListItem(new Other(sec.getAnchor()))); 53 | if ( sec.sections!=null ) { 54 | List subseclist = new ArrayList<>(); 55 | for (Section subsec : sec.sections) { 56 | System.out.println("\t"+subsec.getAnchor()); 57 | subseclist.add(new ListItem(new Other(subsec.getAnchor()))); 58 | } 59 | seclist.add(new ListItem(new UnOrderedList(subseclist))); 60 | } 61 | } 62 | return new UnOrderedList(seclist); 63 | } 64 | return null; 65 | } 66 | */ 67 | } 68 | -------------------------------------------------------------------------------- /oldsrc/us/parr/bookish/util/DataTable.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.util; 2 | 3 | import org.apache.commons.csv.CSVFormat; 4 | import org.apache.commons.csv.CSVParser; 5 | import org.apache.commons.csv.CSVRecord; 6 | import org.apache.commons.lang3.math.NumberUtils; 7 | import org.apache.commons.math3.util.Precision; 8 | 9 | import java.io.Reader; 10 | import java.io.StringReader; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Set; 14 | 15 | import static us.parr.lib.ParrtStrings.abbrevString; 16 | 17 | public class DataTable { 18 | public List colNames = new ArrayList<>(); 19 | public List> rows = new ArrayList<>(); 20 | public boolean firstColIsIndex; 21 | 22 | public DataTable(String csv) {//, int firstDataRow) { 23 | parseCSV(csv); 24 | } 25 | 26 | public void parseCSV(String csv) { 27 | try { 28 | Reader in = new StringReader(csv); 29 | CSVFormat format = CSVFormat.EXCEL.withHeader(); 30 | CSVParser parser = format.parse(in); 31 | this.firstColIsIndex = false; 32 | for (CSVRecord record : parser) { 33 | if ( !firstColIsIndex && Character.isAlphabetic(record.get(0).charAt(0)) ) { 34 | // latch if we see alpha not number 35 | firstColIsIndex = true; 36 | } 37 | List row = new ArrayList<>(); 38 | for (int i = 0; i colNames = parser.getHeaderMap().keySet(); 59 | if ( !firstColIsIndex ) { 60 | colNames.remove(""); // remove index column name 61 | } 62 | this.colNames.addAll(colNames); 63 | } 64 | catch (Exception e) { 65 | throw new RuntimeException(e); 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/us/parr/bookish/translate/HTMLEscaper.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.translate; 2 | 3 | import org.stringtemplate.v4.StringRenderer; 4 | import us.parr.lib.ParrtCollections; 5 | 6 | import java.util.Locale; 7 | import java.util.regex.Pattern; 8 | 9 | public class HTMLEscaper extends StringRenderer { 10 | @Override 11 | public String toString(Object o, String formatString, Locale locale) { 12 | String s = (String)o; 13 | if ( formatString!=null ) { 14 | switch ( formatString ) { 15 | case "xml-encode": 16 | s = escape(s); 17 | s = highlight(s); 18 | break; 19 | case "highlight" : 20 | s = highlight(s); 21 | break; 22 | } 23 | return s; 24 | } 25 | return super.toString(o, null, locale); 26 | } 27 | 28 | public static String highlight(String s) { 29 | if ( s==null || s.length()==0 ) return s; 30 | // lines beginning with '!' are to be highlighted so 31 | // dehighlight all the others. 32 | Pattern c = Pattern.compile("^!", Pattern.MULTILINE); 33 | if ( c.matcher(s).find() ) { // any line starts with '!'? 34 | String[] lines = s.split("\\n"); 35 | for (int i = 0; i" + lines[i].substring(1) + ""; 38 | } 39 | } 40 | s = ParrtCollections.join(lines, "\n"); 41 | } 42 | return s; 43 | } 44 | 45 | public static String stripBangs(String s) { 46 | if ( s==null || s.length()==0 ) return s; 47 | // strip '!' on start of lines 48 | Pattern c = Pattern.compile("^!", Pattern.MULTILINE); 49 | if ( c.matcher(s).find() ) { // any line starts with '!'? 50 | String[] lines = s.split("\\n"); 51 | for (int i = 0; i dataFilesToCopy = new ArrayList<>(); 32 | 33 | public String copyright; // translated to output target 34 | 35 | /** Abstract tag in book or article root file, not chapter file(s) */ 36 | public String abstract_; // translated to output target 37 | 38 | public List notebookResources = new ArrayList<>(); 39 | 40 | public Map metadata; 41 | 42 | public RootDocInfo rootdoc; 43 | public List docs = new ArrayList<>(); 44 | 45 | /** Attributes of the book or article tag in root file */ 46 | public Map attributes; 47 | 48 | public STGroup templates; 49 | 50 | public Artifact(Tool tool, String title) { 51 | this.tool = tool; 52 | this.title = title; 53 | templates = loadTemplates(); 54 | } 55 | 56 | public void addRootDoc(RootDocInfo rootdoc) { 57 | this.rootdoc = rootdoc; 58 | this.rootdoc.artifact = this; 59 | this.attributes = rootdoc.attributes; 60 | } 61 | 62 | public void addDoc(ChapDocInfo doc) { 63 | docs.add(doc); 64 | doc.artifact = this; 65 | } 66 | 67 | public EntityDef getEntity(String label) { 68 | return rootdoc.getEntity(label); 69 | } 70 | 71 | /** Define global entity */ 72 | public void defGlobalEntity(String label, EntityDef d) { 73 | rootdoc.defEntity(label, d); 74 | } 75 | 76 | public abstract STGroup loadTemplates(); 77 | } 78 | -------------------------------------------------------------------------------- /src/us/parr/bookish/entity/EntityDef.java: -------------------------------------------------------------------------------- 1 | package us.parr.bookish.entity; 2 | 3 | import org.antlr.v4.runtime.Token; 4 | import org.stringtemplate.v4.ST; 5 | import us.parr.bookish.model.OutputModelObject; 6 | 7 | import java.util.Map; 8 | import java.util.Objects; 9 | 10 | public class EntityDef { 11 | public EntityWithScope enclosingScope; 12 | 13 | public String label; // optional label 14 | 15 | /** indexed from 1; fig, citation, sidenote number. 16 | * Does not track chp/sec numbers. Those are done via 17 | * ContainerWithTitle.connectContainerTree(). 18 | */ 19 | public int index; 20 | 21 | /** Useful to determine if we should generate code for this ref. 22 | * We avoid dup code gen this way. 23 | */ 24 | public int refCount = 0; 25 | 26 | public Map attributes; 27 | public OutputModelObject model; 28 | public ST template; 29 | public Token startToken; 30 | 31 | public EntityDef(int index, Map attributes) { 32 | this(index, attributes, null); 33 | } 34 | 35 | public EntityDef(int index, Map attributes, Token startToken) { 36 | this.index = index; 37 | this.attributes = attributes; 38 | this.startToken = startToken; 39 | if ( attributes!=null ) { // get a common attribute 40 | this.label = attributes.get("label"); 41 | } 42 | } 43 | 44 | public boolean isGloballyVisible() { return false; } 45 | 46 | public Token getStartToken() { return startToken; } 47 | 48 | public boolean isSideItem() { return false; } 49 | 50 | /** Return string indicating which section or chapter number */ 51 | public String getEntityID() { 52 | if ( enclosingScope==null ) { 53 | return String.valueOf(index); 54 | } 55 | return enclosingScope.getEntityID()+'.'+String.valueOf(index); 56 | } 57 | 58 | public ChapterDef getEnclosingChapter() { 59 | if ( enclosingScope==null ) { 60 | return null; 61 | } 62 | if ( enclosingScope instanceof ChapterDef ) { 63 | return (ChapterDef)enclosingScope; 64 | } 65 | return enclosingScope.getEnclosingChapter(); 66 | } 67 | 68 | 69 | @Override 70 | public boolean equals(Object o) { 71 | if ( this==o ) return true; 72 | if ( !(o instanceof EntityDef) ) return false; 73 | EntityDef entityDef = (EntityDef) o; 74 | return Objects.equals(label, entityDef.label); 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | return Objects.hash(label); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return '<'+label+":"+this.getClass().getSimpleName()+'>'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /images/xT.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /resources/templates/pyeval.stg: -------------------------------------------------------------------------------- 1 | delimiters "<",">" 2 | 3 | pyfile(snippets, buildDir, outputDir, basename, label) ::= << 4 | import io 5 | import sys 6 | from pandas import DataFrame 7 | from contextlib import redirect_stdout, redirect_stderr 8 | 9 | def dump(o, display_expr): 10 | """Given df, col, ndarray, value return csv formatted data""" 11 | # write to 12 | display_expr = display_expr.strip() 13 | if type(o)==DataFrame: 14 | return o.to_csv(index=True) 15 | else: 16 | return str(o) 17 | 18 | 19 | >> 20 | 21 | pyfig(def,code) ::= << 22 | # snippet 23 | import matplotlib.pyplot as plt 24 | import matplotlib as mpl 25 | fstderr = io.StringIO() 26 | with redirect_stderr(fstderr): 27 | try: 28 | fig__ = plt.figure(999999, clear=True) # clear previous fig 999999 29 | mpl.rcParams['font.size'] = 14 30 | mpl.rcParams['figure.figsize'] = [4.0, 3.0] 31 | mpl.rcParams['savefig.bbox'] = 'tight' 32 | mpl.rcParams['savefig.pad_inches'] = '0.5' 33 | mpl.rcParams['legend.fontsize'] = 16 34 | 35 | plt.savefig("/images//_