-
Notifications
You must be signed in to change notification settings - Fork 2
/
argmap2mup
executable file
·603 lines (587 loc) · 14.2 KB
/
argmap2mup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
#!/usr/bin/env lua
local pl = require'pl.import_into'()
local lyaml = require "lyaml"
local json = require 'json'
-- initialize the output map
local output = { ["ideas"] = {}}
-- initialize a global counter for providing unique ids
local gn = 0
-- default options
local gdrive_id = nil
local gdriveFolder = nil
local name = nil
local upload = false
local public = ""
-- a long string containing all the styling needed for argument maps
local template = lyaml.load([=[
---
formatVersion: 3
id: root
attr:
theme: argMappingSimple
theme:
name: 'MindMup Top Down Argument Mapping'
connectorEditingContext:
name: argument-mapping
allowed:
- width
- label
defaults:
width: 3
blockThemeOverrides: true
layout:
orientation: top-down
spacing:
h: 20
v: 60
node:
-
name: default
cornerRadius: 5
backgroundColor: '#ffffff'
border:
type: surround
line:
color: '#707070'
width: 1
shadow:
-
color: '#070707'
opacity: 0.3
offset:
width: 2
height: 2
radius: 2
text:
margin: 5
alignment: start
maxWidth: 146
color: '#4F4F4F'
lightColor: '#EEEEEE'
darkColor: '#000000'
font:
lineSpacing: 2
lineSpacingPx: 2.6
size: 10
sizePx: 13.3
weight: light
connections:
default:
h: center-separated
v: base
from:
horizontal:
h: center-separated
v: base
to:
h: center
v: top
decorations:
height: 16
edge: top
overlap: true
position: end
-
name: attr_implicit_claim
border:
type: surround
line:
color: '#707070'
width: 1
style: dashed
-
name: activated
border:
type: surround
line:
color: '#22AAE0'
width: 3
style: dotted
-
name: activated.attr_implicit_claim
border:
type: surround
line:
color: '#22AAE0'
width: 3
style: dashed
-
name: selected
shadow:
-
color: '#000000'
opacity: 0.9
offset:
width: 2
height: 2
radius: 2
-
name: collapsed
shadow:
-
color: '#888888'
offset:
width: 0
height: 1
radius: 0
-
color: '#FFFFFF'
offset:
width: 0
height: 3
radius: 0
-
color: '#888888'
offset:
width: 0
height: 4
radius: 0
-
color: '#FFFFFF'
offset:
width: 0
height: 6
radius: 0
-
color: '#888888'
offset:
width: 0
height: 7
radius: 0
-
name: collapsed.selected
shadow:
-
color: '#FFFFFF'
offset:
width: 0
height: 1
radius: 0
-
color: '#888888'
offset:
width: 0
height: 3
radius: 0
-
color: '#FFFFFF'
offset:
width: 0
height: 6
radius: 0
-
color: '#555555'
offset:
width: 0
height: 7
radius: 0
-
color: '#FFFFFF'
offset:
width: 0
height: 10
radius: 0
-
color: '#333333'
offset:
width: 0
height: 11
radius: 0
-
name: attr_group
cornerRadius: 10
backgroundColor: transparent
border:
type: overline
shadow:
-
color: transparent
text:
margin: 0
alignment: center
color: '#4F4F4F'
lightColor: '#EEEEEE'
darkColor: '#000000'
font:
lineSpacing: 2.5
lineSpacingPx: 3.25
size: 9
sizePx: 12
weight: bold
connections:
style: supporting-group
childstyle: no-connector
default:
h: center
v: base
from:
below:
h: center
v: base
to:
h: center
v: top
-
name: attr_group_supporting
connections:
style: supporting-group
childstyle: no-connector
default:
h: center
v: base
from:
below:
h: center
v: base
to:
h: center
v: top
-
name: attr_group_supporting.level_1
backgroundColor: 'rgba(0, 255, 0, 0.2)'
border:
type: surround
line:
color: transparent
width: 2
style: solid
-
name: attr_group_supporting.activated
backgroundColor: 'rgba(0, 255, 0, 0.2)'
border:
type: surround
line:
color: '#00FF00'
width: 3
style: dotted
-
name: attr_group_opposing
connections:
style: opposing-group
childstyle: no-connector
default:
h: center
v: base
from:
below:
h: center
v: base
to:
h: center
v: top
-
name: attr_group_opposing.level_1
backgroundColor: 'rgba(255, 0, 0, 0.2)'
border:
type: surround
line:
color: transparent
width: 2
style: solid
-
name: attr_group_opposing.activated
backgroundColor: 'rgba(255, 0, 0, 0.2)'
border:
type: surround
line:
color: '#FF0000'
width: 3
style: dotted
-
name: attr_group_supporting.droppable
backgroundColor: 'rgba(0, 255, 0, 0.6)'
border:
type: surround
line:
color: '#00FF00'
width: 3
style: dashed
-
name: attr_group_opposing.droppable
backgroundColor: 'rgba(255, 0, 0, 0.6)'
border:
type: surround
line:
color: '#FF0000'
width: 3
style: dashed
connector:
default:
type: vertical-quadratic-s-curve
line:
color: '#707070'
width: 1
label:
position:
aboveEnd: 15
ratio: 0.8
backgroundColor: white
borderColor: white
text:
color: '#4F4F4F'
font:
size: 9
sizePx: 12
weight: normal
no-connector:
type: no-connector
line:
color: '#707070'
width: 0
supporting-group:
type: vertical-quadratic-s-curve
line:
color: '#339966'
width: 3
label:
position:
aboveEnd: 15
ratio: 0.8
backgroundColor: white
borderColor: white
text:
color: '#339966'
font:
size: 9
sizePx: 12
weight: normal
opposing-group:
type: vertical-quadratic-s-curve
line:
color: '#FF0000'
width: 3
label:
position:
aboveEnd: 15
ratio: 0.8
backgroundColor: white
borderColor: white
text:
color: '#FF0000'
font:
size: 9
sizePx: 12
weight: normal
no-connector.supporting-group:
type: no-connector
line:
color: '#339966'
width: 4
label:
position:
ratio: 0.5
backgroundColor: transparent
borderColor: transparent
text:
color: '#339966'
font:
size: 6
sizePx: 9
weight: normal
no-connector.opposing-group:
type: no-connector
line:
color: '#FF0000'
width: 4
label:
position:
ratio: 0.5
backgroundColor: transparent
borderColor: transparent
text:
color: '#4F4F4F'
font:
size: 6
sizePx: 9gg
weight: normal
...
]=])
function pipe_in_out(cmd, s)
-- a function for piping through unix commands
local tmp = os.tmpname()
local tmpout = os.tmpname()
local f = io.open(tmp, 'w')
f:write(s)
f:close()
local fout = assert(io.popen(cmd .. " " .. tmp))
local o = fout:read("*all")
fout:close()
os.remove(tmp)
os.remove(tmpout)
return o
end
local function trim(s)
-- trim trailing newlines
return (s:gsub("\n",""))
end
function markdown_to_plain(s)
return trim(pipe_in_out("pandoc --wrap=none -t plain -f markdown", s))
end
function parse_special(t,s)
-- a function for parsing notes, labels, and strengths
for i,v in pairs(t) do
if string.match(i, "^" .. s .. "$") then
return v
end
end
return nil
end
function parse_claims(t)
-- initialize the output table
local o = {}
-- initialize a local counter for ids
local n = 0
for i,v in pairs(t) do
if not string.match(i, "^label$") and not string.match(i, "^strength$") then
-- manage counters
n = n + 1
gn = gn + 1
local id = tostring(n)
local gid = tostring(gn)
-- the key is the claim
local claim = i
-- if we haven't set a name for our map yet, use the claim as the name.
if not name then
name = claim
end
local attr = {}
-- claims that begin with a '-' are styled as implicit premises
if string.match(claim,"^-.*") then
claim = string.sub(claim,2,-1)
attr = {
["styleNames"] = { "attr_implicit_claim" }
}
end
claim = markdown_to_plain(claim)
local note = parse_special(v,"note")
if note then
note = markdown_to_plain(note)
gn = gn + 1
attr["note"] = {
["index"] = gn,
["text"] = note
}
end
o[id] = {
["title"] = claim,
["id"] = gid,
["attr"] = attr,
["ideas"] = parse_reasons(v)
}
end
end
return o
end
function parse_reasons(t)
local o = {}
local n = 0
for i,v in pairs(t) do
if not string.match(i, "^note$") then
n = n + 1
gn = gn + 1
local id = tostring(n)
local gid = tostring(gn)
local group = "supporting"
if string.match(i, "^[-o].*") then
group = "opposing"
end
local label = parse_special(v,"label")
local strength = parse_special(v,"strength")
local ideas = parse_claims(v)
local attr = { ["contentLocked"] = "true",
["group"] = group,
["parentConnector"] = { ["width"] = strength, ["label"] = label }
}
o[id] = { ["title"] = "group", ["id"] = gid, ["attr"] = attr, ["ideas"] = ideas }
end
end
return o
end
function help()
return [[argmap2mup <options> <file>
-u, --upload : upload to Google Drive
-g ID, --gdrive_id ID : update file with ID on Google Drive
-f ID, --folder ID : upload to Google Drive folder with ID
-p, --public : mark uploaded file as public
-n NAME, --name NAME : set the name of the map to NAME
-h, --help]]
end
function parse_options(a)
local opts = {}
local flags,args = pl.app.parse_args(a,{g=true, gdrive_id=true, n=true, name=true, f=true, folder=true })
opts["upload"] = flags["u"] or flags["upload"] or
flags["p"] or flags["public"] or
flags["g"] or flags["gdrive"] or
flags["f"] or flags["folder"]
opts["help"] = flags["h"] or flags["help"]
if flags["p"] or flags["public"] then
opts["public"] = "--share"
else
opts["public"] = ""
end
opts["gdrive_id"] = flags["g"]
if not opts["gdrive_id"] then
opts["gdrive_id"] = flags["gdrive_id"]
end
gdriveFolder = flags["f"]
if not gdriveFolder then
gdriveFolder = flags["folder"]
end
name = flags["n"]
if not name then
name = flags["name"]
end
if #args > 0 then
opts["file"] = args[1]
end
return opts
end
function main()
print(args)
local opts = parse_options(args)
if opts["help"] then
return help()
else
local input = ""
if opts["file"] then
local f = io.open(opts["file"],'r')
input = f:read("*all")
f:close()
else
input = io.read("*all")
end
local argmap = lyaml.load(input)
output = template
output["ideas"] = parse_claims(argmap)
output["title"] = name
local mup = json.encode(output)
if opts["upload"] and opts["gdrive_id"] then
pipe_in_out("gdrive update " ..
"--no-progress " ..
"--name \"" .. name .. "\" " ..
"--mime \"application/vnd.mindmup\" ..\" " ..
opts["gdrive_id"] .. "\"",
mup)
return opts["gdrive_id"]
elseif opts["upload"] then
if gdriveFolder then
folderopt = "-p \"" .. gdriveFolder .. "\" "
else
gdriveFolder = nil
end
local gdriveoutput = pipe_in_out(
"gdrive upload --delete " ..
opts["public"] .. " " ..
"--no-progress " ..
folderopt ..
"--name \"" .. name .. "\" " ..
"--mime \"application/vnd.mindmup\"",
mup)
local gdrive_id = string.match(gdriveoutput, "Uploaded ([^%s]*) at")
return gdrive_id
else
return mup
end
end
end
print(main())