Commit bb2f03f 1 parent f56ca8f commit bb2f03f Copy full SHA for bb2f03f
File tree 4 files changed +15
-18
lines changed
4 files changed +15
-18
lines changed Original file line number Diff line number Diff line change 28
28
(defn- gen-abstract-numbering-id []
29
29
(str (swap! (:counter2 *numbering*) inc)))
30
30
31
-
32
- (def ^:private ignorable-tag :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fmarkup-compatibility %2 F2006 /Ignorable )
33
-
34
-
35
31
(defn -add-extra-elems [evaluated-model extra-elems]
36
32
(-> evaluated-model
37
33
(update-in [:main :stencil.model/numbering ]
38
34
(fn [nr#]
39
35
(if (:stencil.model/path nr#)
40
36
(dissoc nr# :source-file )
41
37
(assoc nr#
42
- :parsed {:tag ooxml/tag-numbering :attrs {ignorable-tag " " } :content []}
38
+ :parsed {:tag ooxml/tag-numbering :attrs {ooxml/ ignorable " " } :content []}
43
39
:stencil.model/path " word/numbering.xml" ))))
44
40
; ; TODO: make it conditional
45
41
(assoc-in [:content-types :parsed :stencil.model.content-types/override " /word/numbering.xml" ]
Original file line number Diff line number Diff line change 131
131
; ; drawing, binary large image or picture
132
132
(def blip :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fdrawingml %2 F2006 %2 Fmain /blip )
133
133
; ; hyperlinks
134
- (def hyperlink :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fwordprocessingml %2 F2006 %2 Fmain /hyperlink )
134
+ (def hyperlink :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fwordprocessingml %2 F2006 %2 Fmain /hyperlink )
135
+
136
+ ; ; OOXML attribute holds list of ns aliases
137
+ (def ignorable :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fmarkup-compatibility %2 F2006 /Ignorable )
138
+
139
+ ; ; OOXML tag, has Requires attribute which holds list of ns aliases
140
+ (def choice :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fmarkup-compatibility %2 F2006 /Choice )
Original file line number Diff line number Diff line change 6
6
[clojure.string :as s]
7
7
[stencil.ooxml :as ooxml]))
8
8
9
- (def ^:private ignorable-tag :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fmarkup-compatibility %2 F2006 /Ignorable )
10
- (def ^:private choice-tag :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fmarkup-compatibility %2 F2006 /Choice )
11
9
12
10
; ; like clojure.walk/postwalk but keeps metadata and calls fn only on nodes
13
11
(defn- postwalk-xml [f xml-tree]
27
25
" Updates the Requires attribute of a Choice tag with the fn"
28
26
[elem f]
29
27
(assert (ifn? f))
30
- (if (= (:tag elem) choice-tag )
28
+ (if (= (:tag elem) ooxml/ choice)
31
29
(update-in elem [:attrs :Requires ] f)
32
30
elem))
33
31
40
38
41
39
; ; first call this
42
40
(defn map-ignored-attr
43
- " Replaces values in ignorable-tag and requires-tag attributes to
41
+ " Replaces values in Ignorable and Requires attributes to
44
42
the namespace names they are aliased by."
45
43
[xml-tree]
46
44
(postwalk-xml
47
45
(fn [form]
48
46
(let [p->url (get-in (meta form) [:clojure.data.xml/nss :p->u ])]
49
47
(-> form
50
- (update-if-present [:attrs ignorable-tag ] (partial map-str p->url))
48
+ (update-if-present [:attrs ooxml/ ignorable] (partial map-str p->url))
51
49
(update-choice-requires (partial map-str p->url)))))
52
50
xml-tree))
53
51
67
65
(when (contains? ooxml/default-aliases ns )
68
66
(find! ns )))
69
67
(-> form
70
- (update-if-present [:attrs ignorable-tag ] (partial map-str find!))
68
+ (update-if-present [:attrs ooxml/ ignorable] (partial map-str find!))
71
69
(update-choice-requires (partial map-str find!))))
72
70
xml-tree)
73
71
@found)))
Original file line number Diff line number Diff line change 1
1
(ns stencil.ignored-tag-test
2
2
(:require [clojure.data.xml :as xml]
3
- [clojure.java.io :as io]
4
- [clojure.walk :as walk]
5
- [clojure.test :refer [deftest is are testing]]
3
+ [clojure.test :refer [deftest is testing]]
6
4
[stencil.tokenizer :as tokenizer]
7
5
[stencil.merger :as merger]
6
+ [stencil.ooxml :as ooxml]
8
7
[stencil.postprocess.ignored-tag :refer :all ]))
9
8
10
9
; ; make all private maps public!
36
35
(java.io.StringReader. ) (merger/parse-to-tokens-seq ) (tokenizer/tokens-seq->document )
37
36
(clear-all-metas ) (unmap-ignored-attr ) (xml/emit-str ) (xml/parse-str )
38
37
(as-> *
39
- (let [ignorable-value
40
- (-> * :content first :attrs
41
- :xmlns.http%3 A%2 F%2 Fschemas.openxmlformats.org%2 Fmarkup-compatibility%2 F2006/Ignorable)
38
+ (let [ignorable-value (-> * :content first :attrs ooxml/ignorable)
42
39
ignorable-ns (-> * meta :clojure.data.xml/nss :p->u (get ignorable-value))]
43
40
(is (not (empty? ignorable-value)))
44
41
(is (= " ns2" ignorable-ns)))))))
You can’t perform that action at this time.
0 commit comments