Commit 510635e 1 parent 8306f4f commit 510635e Copy full SHA for 510635e
File tree 2 files changed +13
-4
lines changed
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 73
73
74
74
(def attr-ilvl :xmlns.http %3 A %2 F %2 Fschemas.openxmlformats.org %2 Fwordprocessingml %2 F2006 %2 Fmain /ilvl )
75
75
76
+ (def tag-imagedata :xmlns.urn %3 Aschemas-microsoft-com %3 Avml /imagedata )
77
+
76
78
(def default-aliases
77
79
{; default namespace aliases from a LibreOffice 6.4 OOXML Text document
78
80
" http://schemas.openxmlformats.org/markup-compatibility/2006" " mc"
Original file line number Diff line number Diff line change 35
35
{:mime-type (.toLowerCase (.substring data-uri-str 5 end-of-mimetype))
36
36
:bytes (.decode (java.util.Base64/getDecoder ) (.getBytes (.substring data-uri-str start-of-data)))}))
37
37
38
+
39
+ ; ; mapping of tag name to attribute for nodes that represent an image and have an attribute for relation id.
40
+ (def ^:private img-tag-attr
41
+ {ooxml/blip ooxml/r-embed
42
+ ooxml/tag-imagedata ooxml/r-id})
43
+
38
44
(defn- update-image [img-node, ^ReplaceImage data]
39
- (assert (= ooxml/blip (:tag img-node)))
45
+ (assert (img-tag-attr (:tag img-node)))
40
46
(assert (instance? ReplaceImage data))
41
- (let [current-rel (-> img-node :attrs ooxml/r-embed)
47
+ (let [attr-key (img-tag-attr (:tag img-node))
48
+ current-rel (-> img-node :attrs attr-key)
42
49
new-val (-> data .relation)]
43
50
(assert new-val)
44
51
(log/debug " Replacing image relation {} by {}" current-rel new-val)
45
- (assoc-in img-node [:attrs ooxml/r-embed ] new-val)))
52
+ (assoc-in img-node [:attrs attr-key ] new-val)))
46
53
47
54
(defn- replace-image [marker-loc]
48
55
(if-let [img-loc (->> (zip/remove marker-loc)
49
56
(iterations zip/prev)
50
- (find-first (comp #{ooxml/blip} :tag zip/node)))]
57
+ (find-first (comp img-tag-attr :tag zip/node)))]
51
58
(zip/edit img-loc update-image (zip/node marker-loc))
52
59
(fail " Did not find image to replace. The location of target image must precede the replaceImage() function call location." {})))
53
60
You can’t perform that action at this time.
0 commit comments