/******************************************************************************/ /* */ /* svg2md2draw.rex - An SVG to a group of md2slides */ /* ================================================ */ /* */ /* This program is part of the Rexx Parser package */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2024-2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /* Date Version Details */ /* -------- ------- --------------------------------------------------------- */ /* 20261014 0.7 First version */ /* */ /******************************************************************************/ /* */ /* [rexx] svg2md2draw [options] drawing.svg [group.md2draw] */ /* */ /* Writes a box-and-arrow SVG as a group of md2slides: a .md2draw file, by */ /* default beside the SVG, with the extension .md2draw; "-" writes it to the */ /* standard output. A deck uses it with '. use drawing.md2draw at=...' (see */ /* the header of the file). What a drawing of md2slides cannot hold is left */ /* out and listed. See svg2md2draw.cls. */ /* */ /* Options: */ /* */ /* -h, --help this help */ /* -q, --quiet do not list what was left out */ /* --name NAME the group's name (by default, the file's) */ /* --skin no colours: the deck's skin gives them */ /* */ /******************************************************************************/ CLIhelper = InitCLI() myName = CLIhelper~name myHelp = CLIhelper~help args = CLIhelper~args quiet = 0 skin = 0 name = "" files = .Array~new Loop i = 1 To args~items a = args[i] Select Case Lower(a) When "-h", "--help", "-?" Then Signal Help When "-q", "--quiet" Then quiet = 1 When "--skin" Then skin = 1 When "--name" Then Do i += 1 If i > args~items Then Call Fail "--name wants a name" name = args[i]~strip("L", "#") If \IsName(name) Then Call Fail "'"name"' cannot be a name: a letter, then letters, digits, - or _" End Otherwise Do If a~left(1) == "-", a \== "-" Then Call Fail "unknown option '"a"'" files~append(a) End End End If files~items == 0 | files~items > 2 Then Signal Help in = files[1] If \SysFileExists(in) Then Call Fail "'"in"' does not exist" s = .Stream~new(in) lines = s~arrayIn s~close base = in dot = base~lastPos(".") If dot > base~lastPos("/"), dot > base~lastPos("\") Then base = base~left(dot - 1) If files~items == 2 Then out = files[2] Else out = base".md2draw" short = base~substr(Max(base~lastPos("/"), base~lastPos("\")) + 1) If name == "" Then Do name = short~translate("--", " .") If \IsName(name) Then name = "drawing" End title = in~substr(Max(in~lastPos("/"), in~lastPos("\")) + 1) file = out~substr(Max(out~lastPos("/"), out~lastPos("\")) + 1) If out == "-" Then file = short".md2draw" conv = .SVG.MD2DRAW~new md = conv~md2draw(lines, name, title, skin, file) If md~items == 0 Then Call Fail "'"in"' has no drawing in it" If out == "-" Then Do line Over md; Say line; End Else Do Call SysFileDelete out o = .Stream~new(out) o~open("Write Replace") o~arrayOut(md) o~close If \quiet Then Say myName": wrote" out "(group #"name")" End If \quiet Then Do note Over conv~notes .Error~lineOut(myName": left out:" note) End Exit 0 Help: Say myName "[-q] [--skin] [--name NAME] drawing.svg [group.md2draw | -]" Say "Writes a box-and-arrow SVG as a group of md2slides. Documentation:" myHelp Exit 1 Fail: .Error~lineOut(myName":" Arg(1)) Exit 1 ::Requires "parser/CLISupport.cls" ::Requires "svg2md2draw.cls"