Skip to main content

render

diya.render(text, options)​

const svg = diya.render(`A B C`, {padding: 20});

Renders Diya text and returns an SVGSVGElement, sized to its content. Invalid text throws a DiyaError.

Options​

options override the text's --- config:

  • padding - space around the content, in pixels (default 10)
  • rowGap - space between the sketch's rows (default 12)
  • columnGap - space between the sketch's columns (default 20)

Any other option is an error.

diya.parse(text)​

const {sketch, relations, styles, config} = diya.parse(`A B
--- relations
stack [A B]`);

Parses Diya text into its sections without laying it out, and throws a DiyaError on a syntax error. Returns an object:

  • sketch - the rows, each {cells, line}, where a cell is text, empty or a span
  • relations - the statements, each with its verb, id, classes, groups of references, properties and line
  • styles - the rules, each with its selectors, properties and line
  • config - the settings, as an object

diya.DiyaError​

try {
diya.render(text);
} catch (error) {
if (error instanceof diya.DiyaError) console.log(error.line, error.message);
}

The error Diya throws for invalid text. Its message starts with Line N: when the error is on a line, and its line property is that line number (from 1), or undefined. Messages say how to fix the error: an ambiguous reference lists its matches and how to narrow them, and a feature that isn't built yet says so.