Browse Source

add image tag

master
munir ishak 4 years ago
parent
commit
a9aca93578
1 changed files with 34 additions and 0 deletions
  1. 34
    0
      index.js

+ 34
- 0
index.js View File

@@ -180,6 +180,26 @@ var exchange_text = exports.exchange_text = function exchange_text(text, options
180 180
                     temp = temp + ch;
181 181
                 }
182 182
             }
183
+            else if (text.substring(i, i+5) == "<IMG>")
184
+            {
185
+                index = text.indexOf("</IMG>", i + 5);
186
+                if (index != -1)
187
+                {
188
+                    var url = text.substring(i + 5, index);
189
+                    bytes.concat(align_center_bytes);
190
+                    bytes.concat(none_space_bytes);
191
+                    bytes.concat(change_base64_to_bytes(url));
192
+                    // console.log("change_image_url_to_bytes:",change_image_url_to_bytes(url))
193
+                    // console.log("change_base64_to_bytes:",change_base64_to_bytes(url))
194
+                    bytes.concat(default_space_bytes);
195
+                    bytes.concat(align_left_bytes);
196
+                    i = index + 5;
197
+                }
198
+                else
199
+                {
200
+                    temp = temp + ch;
201
+                }
202
+            }
183 203
             else if (text.substring(i, i+5) == "<QRI>")
184 204
             {
185 205
                 index = text.indexOf("</QRI>", i + 5);
@@ -245,6 +265,20 @@ var exchange_text = exports.exchange_text = function exchange_text(text, options
245 265
     return bytes.toBuffer();
246 266
 }
247 267
 
268
+var change_base64_to_bytes = exports.change_base64_to_bytes = function change_base64_to_bytes(base64){
269
+    var raw = window.atob(base64);
270
+    var rawLength = raw.length;
271
+    var array = new Uint8Array(new ArrayBuffer(rawLength));
272
+
273
+    for(i = 0; i < rawLength; i++) {
274
+        array[i] = raw.charCodeAt(i);
275
+    }
276
+    return array;
277
+
278
+}
279
+
280
+
281
+
248 282
 var change_image_url_to_bytes = exports.change_image_url_to_bytes = function change_image_url_to_bytes(url, options){
249 283
     options = options||{
250 284
         encoding: 'UTF8'

Loading…
Cancel
Save