Giter Club home page Giter Club logo

code2xml's Introduction

code2xml

Convert source code to syntax-annotated XML

Abstract

This is a small command-line utility to convert source code to syntax-annotated XML. It is intended to simplify the importing of arbitrary source code artifacts as syntax-highlighted source code text into Adobe InDesign with the help of its Import XML mechanism. Internally, code2xml uses the Node.js Syntax module for highlighting the source code fragments with XML tags named <xxx-root> (root element), <xxx-block[-XXX]> (enclosure element), <xxx-comment>, <xxx-keyword>, <xxx-literal>, <xxx-marker> and <xxx-anchor-N>. Use the Adobe InDesign Map Tags to Styles functionality to map those XML tags to Adobe InDesign styles.

Installation

$ npm install -g code2xml

Usage

$ code2xml [-h] [-V] [-l <language>] [-o <output-file>] [-f <input-file>]
  • -h, --help
    Show usage help.
  • -V, --version
    Show program version information.
  • -l <language>, --language <language>
    Either "auto" (the default) or one of the languages understood by the Syntax module.
  • -i <id>, --id <id>
    Either "" (the default for none) or an identifier to append to the name of the enclosure XML element <xxx-block>.
  • -p <prefix>, --prefix <prefix>
    Either "syntax-" (the default) or an identifier to prepend to the name of all XML elements.
  • --without-declaration
    Do not emit XML declaration.
  • --without-root
    Do not emit root element <xxx-root>.
  • --without-file
    Do not emit file element <xxx-file[-XXX]>.
  • --without-block
    Do not emit block element <xxx-block>.
  • --tab-replace <string>
    replace TAB characters with this string.
  • --newline-replace <string>
    replace [CR+]LF characters with this string.
  • --regex-anchor-open <regex>
    use this regular expression for anchor opening constructs.
  • --regex-anchor-close <regex>
    use this regular expression for anchor closing constructs.
  • --regex-marker-open <regex>
    use this regular expression for marker opening constructs.
  • --regex-marker-close <regex>
    use this regular expression for marker closing constructs.
  • -o <output-file>, --output <output-file>
    Either "-" (the default for stdout) or a path to the XML output file.
  • -f <input-file>, --file <input-file>
    Either "-" (the default for stdin) or a path to the source code input file.

Example

$ cat sample.js
/* sample comment */
const foo = (arg1, arg2=(1)=, arg3) => {
    var foo  = 42
={    var bar  = "baz"    }= =(2)=
    var quux = /foo\/bar"quux"/
    return foo + bar + quux
}

$ code2xml -f sample.js
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<syntax-root><syntax-file><syntax-block><syntax-comment>/* sample comment */</syntax-comment>
<syntax-keyword>const</syntax-keyword> foo = (arg1, arg2<syntax-anchor-1></syntax-anchor-1>, arg3) =&gt; {
    <syntax-keyword>var</syntax-keyword> foo  = <syntax-literal>42</syntax-literal>
<syntax-marker>    </syntax-marker><syntax-keyword><syntax-marker>var</syntax-marker></syntax-keyword><syntax-marker> bar  = </syntax-marker><syntax-literal><syntax-marker>"baz"</syntax-marker></syntax-literal><syntax-marker>    </syntax-marker> <syntax-anchor-2></syntax-anchor-2>
    <syntax-keyword>var</syntax-keyword> quux = <syntax-literal>/foo\/bar"quux"/</syntax-literal>
    <syntax-keyword>return</syntax-keyword> foo + bar + quux
}
</syntax-block></syntax-file></syntax-root>

License

Copyright (c) 2016-2022 Dr. Ralf S. Engelschall (http://engelschall.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

code2xml's People

Contributors

rse avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.