• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / jdita / a7766ea3-980a-4afe-844e-9324f17748d0

18 Apr 2024 01:08PM UTC coverage: 84.65% (-1.2%) from 85.85%
a7766ea3-980a-4afe-844e-9324f17748d0

Pull #136

circleci

marmoure
Revert "[doc] update `serializeToXML` info in the README"

This reverts commit 0fcee1b26.
Pull Request #136: Feature "XDita Serialization of the AST" (#2731)

426 of 539 branches covered (79.04%)

Branch coverage included in aggregate %.

49 of 76 new or added lines in 6 files covered. (64.47%)

13 existing lines in 1 file now uncovered.

1096 of 1259 relevant lines covered (87.05%)

20.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/lwdita-xdita/example.ts
1
import { xditaToJson, serializeToXML } from "./converter";
2
import { storeOutputXML } from "./utils";
3
import path from 'path';
4
import fs from 'fs';
5

6
const xml =
NEW
7
  `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE topic PUBLIC "-//OASIS//DTD LIGHTWEIGHT DITA Topic//EN" "lw-topic.dtd"><topic id="intro-product"><title><ph keyref="product-name"/>Overview</title><shortdesc>The<ph keyref="product-name"/> kit allows you to operate network-based home lighting through a remote control</shortdesc><body><p id="cdataTest"><![CDATA[ &%<tagname/><!--comment-->]]>The<ph keyref="product-name"/> kit includes a wireless smart lighting system that helps make the lighting in your home more energy efficient and easier to manage. The kit includes the following components:</p><dl><dlentry><dt>Remote Control</dt><dd><p>Allows you to power on, power off, and dim groups of lights on your network.</p></dd></dlentry><dlentry><dt>LED Light Bulbs</dt><dd><p>Energy-efficient network light bulbs you can install into standard light fixtures.</p></dd></dlentry></dl><fig><title><ph keyref="product-name"/>ready for installation</title><image href="../images/kit.png"><alt>Remote Lighting Kit</alt></image></fig><p id="warning">Electrical hazards can cause burns, shocks and electrocution (death).</p></body></topic>`
×
8
/**
9
 * XML example for testing a conversion
10
 *
11
 * @remarks
12
 * This is the entry point given xml string.
13
 * The xml needs to be preprocessed to remove all of the white space
14
 * and new lines from outside of the tags.
15
 *
16
 * @privateRemarks
17
 * TODO: Implement missing handling of newlines and spaces bewtween tags in the input xml,
18
 * because otherwise the first whitespace or linebreak in the XML will be considered as a text node
19
 * and the transformation will break.
20
 *
21
 * @example
22
 * The whitespace needs to be elimited from the XML before processing
23
 * from e.g.:
24
 * ```xml
25
 * <topic>
26
 *   <title>valid title</title>
27
 *   <body>
28
 *     <p>text</p>
29
 *   </body>
30
 * </topic>
31
 * ```
32
 * to this:
33
 * ```xml
34
 * <topic><title>valid title</title><body><p>text</p></body></topic>
35
 * ```
36
 */
NEW
37
xditaToJson(xml)
×
38
  .then(result => {
39
    // Console log an object containing the AST:
NEW
40
    console.log(JSON.stringify(result, null, 2));
×
41

42
    /**
43
     * Start the serialization
44
     * `serializeToXML(root, indentationChar?, tabSize?)` is offering three options to output the document:
45
     * 1. No indentation/formatting - all is output in one line (default)
46
     * 2. Indentation with tabs
47
     * 3. Indentation with Spaces - You can modify the desired number of spaces by setting `indentationSize`, per default it's set to 4 spaces.
48
     */
49

50
    // 1. Default option: The document will have no indentation and will be output in one line
NEW
51
    const res = serializeToXML(result);
×
52

53
    // 2. Comment-in the following line to choose Tabs as indentation
NEW
54
    const tab = '\t';
×
55
    //const res = serializeToXML(result, tab);
56

57
    // 3. Comment-in the following line to choose spaces as indentation
NEW
58
    const space = ' ';
×
NEW
59
    const indentationSize = 4;
×
60
    //const res = serializeToXML(result, space, indentationSize);
61

62
    /**
63
     * For development and testing the above XML example,
64
     * output the XML in a file
65
     * and store it in the filesystem...
66
     */
67

68
    // If the output folder doesn't exist
NEW
69
    const dir = path.join(__dirname, '../../out');
×
NEW
70
    if (!fs.existsSync(dir)) {
×
71
      // create one
NEW
72
      fs.mkdirSync(dir);
×
73
    }
NEW
74
    const outputFile = "/output.xml";
×
NEW
75
    storeOutputXML(res, dir + outputFile);
×
76
    // ...and log the filepath with a success notification
NEW
77
    console.log("Success!\nSaved input to file " + "'./out" + outputFile + "'");
×
78
  })
79
  .catch(e => console.log('Failed to convert:', e));
×
80

81

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc