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

evolvedbinary / jdita / 3bf303d9-a491-4a60-a2ec-d20b4595132f

10 Feb 2024 12:27PM UTC coverage: 84.83% (-1.0%) from 85.85%
3bf303d9-a491-4a60-a2ec-d20b4595132f

Pull #136

circleci

marmoure
[test] add unit tests for visitor and xml tag
Pull Request #136: Feature "XDita Serialization of the AST" (#2731)

428 of 546 branches covered (0.0%)

Branch coverage included in aggregate %.

47 of 62 new or added lines in 7 files covered. (75.81%)

53 existing lines in 19 files now uncovered.

1093 of 1247 relevant lines covered (87.65%)

20.32 hits per line

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

0.0
/packages/lwdita-xml/example.ts
1
/* eslint-disable @typescript-eslint/no-unused-vars */
2
import { xditaToJson, xditaToJdita, serializeToXML } from "./converter";
3
import { BaseNode, TextNode, TopicNode } from "@jdita/lwdita-ast/nodes";
4
import { storeOutputXML } from "./utils";
5
import path from 'path';
6
import fs from 'fs';
7

8
const xml =
NEW
9
  `<?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>`
×
10
/**
11
 * XML example for testing a conversion
12
 *
13
 * @remarks
14
 * This is the entry point given xml string.
15
 * The xml needs to be preprocessed to remove all of the white space
16
 * and new lines from outside of the tags.
17
 *
18
 * @privateRemarks
19
 * TODO: Implement missing handling of newlines and spaces bewtween tags in the input xml,
20
 * because otherwise the first whitespace or linebreak in the XML will be considered as a text node
21
 * and the transformation will break.
22
 *
23
 * @example
24
 * The whitespace needs to be elimited from the XML before processing
25
 * from e.g.:
26
 * ```xml
27
 * <topic>
28
 *   <title>valid title</title>
29
 *   <body>
30
 *     <p>text</p>
31
 *   </body>
32
 * </topic>
33
 * ```
34
 * to this:
35
 * ```xml
36
 * <topic><title>valid title</title><body><<p>text</p></body></topic>
37
 * ```
38
 */
39
xditaToJdita(xml)
×
40
  .then(result => {
41
    // Console log an object containing the AST:
42
    console.log(JSON.stringify(result.json, null, 2));
×
43

44
    /**
45
     * Start the serialization
46
     * The second parameter is the indentation option:
47
     * When set to true, indentation is added to the created XML tree
48
     */
NEW
49
    const res = serializeToXML(result, true).join('');
×
50

51
    /**
52
     * For development and testing the above XML example,
53
     * output the XML in a file
54
     * and store it in the filesystem...
55
     */
56

57
    // If the output folder doesn't exist
NEW
58
    const dir = path.join(__dirname, '../../out');
×
NEW
59
    if (!fs.existsSync(dir)) {
×
60
      // create one
NEW
61
      fs.mkdirSync(dir);
×
62
    }
NEW
63
    const outputFile = "/output.xml";
×
NEW
64
    storeOutputXML(res, dir + outputFile);
×
65
    // ...and log the filepath with a success notification
NEW
66
    console.log("Success!\nSaved input to file " + "'./out" + outputFile + "'");
×
67
  })
68
  .catch(e => console.log('Failed to convert:', e));
×
69

70

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

© 2026 Coveralls, Inc