fixed post rendering to properly display surrogate pair characters
This commit is contained in:
parent
e883b8dcba
commit
5b0a94eca4
2 changed files with 6 additions and 25 deletions
|
@ -149,7 +149,7 @@ Container {
|
|||
topMargin: ui.sdu(2.0)
|
||||
bottomMargin: ui.sdu(2.0)
|
||||
Label {
|
||||
text: Parser.parsePostText(ListItemData.content)
|
||||
text: Parser.fixPostHtml(ListItemData.content.html)
|
||||
multiline: true
|
||||
textFormat: TextFormat.Html
|
||||
navigation.focusPolicy: NavigationFocusPolicy.NotFocusable
|
||||
|
|
|
@ -17,27 +17,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function parsePostText(data) {
|
||||
var t = data.text;
|
||||
data.entities.links.forEach(function(link, indx) {
|
||||
var ltext = t.substring(link.pos, link.pos + link.len);
|
||||
var pretext = t.substring(0, link.pos);
|
||||
var postext = t.substring(link.pos + link.len);
|
||||
pretext = convert(pretext);
|
||||
ltext = convert(ltext);
|
||||
postext = convert(postext);
|
||||
t = pretext + "<a href=\"" + link.link + "\">" + ltext + "</a>" + postext;
|
||||
});
|
||||
return t;
|
||||
}
|
||||
|
||||
function convert(t) {
|
||||
if (t.indexOf('<a href=') > 0) {
|
||||
return t;
|
||||
}
|
||||
t = t.replace(/&/g, "&");
|
||||
t = t.replace(/<3/g, "\u2764");
|
||||
t = t.replace(/</g, "<");
|
||||
t = t.replace(/>/g, ">");
|
||||
return t;
|
||||
function fixPostHtml(data) {
|
||||
data = data.replace(/<\\?\/?span[^>]*>/g, "");
|
||||
data = data.replace(/<br>/g, "<br/>");
|
||||
return data;
|
||||
}
|
Reference in a new issue