From 3a2dee0979468cd56aaba829dbf3f435e52f38ac Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Mon, 15 Jan 2018 08:23:46 -0800 Subject: [PATCH] replace html parsing with text rendering and link parsing function issue #37 --- assets/PostItem.qml | 2 +- assets/parser.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/PostItem.qml b/assets/PostItem.qml index cb61409..65d3f17 100644 --- a/assets/PostItem.qml +++ b/assets/PostItem.qml @@ -146,7 +146,7 @@ Container { topMargin: ui.sdu(2.0) bottomMargin: ui.sdu(2.0) Label { - text: Parser.parsePostData(ListItemData.content.html) + text: Parser.parsePostText(ListItemData.content) multiline: true textFormat: TextFormat.Html navigation.focusPolicy: NavigationFocusPolicy.NotFocusable diff --git a/assets/parser.js b/assets/parser.js index 2b5202f..877dbca 100644 --- a/assets/parser.js +++ b/assets/parser.js @@ -17,6 +17,15 @@ * along with this program. If not, see . */ +function parsePostText(data) { + var t = data.text; + data.entities.links.forEach(function(link, indx) { + var ltext = t.substring(link.pos, link.pos + link.len); + t = t.substring(0, link.pos) + "" + ltext + "" + t.substring(link.pos + link.len); + }); + return t; +} + function parsePostData(t) { t = t.replace(/!/g,"\u0021"); t = t.replace(/"/g,"\u0022");