mirror of https://github.com/zedeus/nitter
notes: don't emit paragraphs for atomic blocks
This commit is contained in:
parent
90f8b074d2
commit
eebaa7b748
|
@ -28,17 +28,17 @@
|
|||
margin: 30px 0;
|
||||
word-wrap: break-word;
|
||||
white-space: break-spaces;
|
||||
}
|
||||
|
||||
.image {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
&>span.image {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
|
||||
img,
|
||||
video {
|
||||
max-width: 100%;
|
||||
border-radius: 20px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
img,
|
||||
video {
|
||||
max-width: 100%;
|
||||
border-radius: 20px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,48 +20,11 @@ proc renderMiniAvatar(user: User; prefs: Prefs): VNode =
|
|||
img(class=(prefs.getAvatarClass & " mini"), src=url)
|
||||
|
||||
proc renderNoteParagraph(articleParagraph: ArticleParagraph; article: Article; tweets: Table[int64, Tweet]; path: string; prefs: Prefs): VNode =
|
||||
let text = articleParagraph.text
|
||||
|
||||
case articleParagraph.baseType
|
||||
of ArticleType.headerOne:
|
||||
result = h1.newVNode()
|
||||
of ArticleType.headerTwo:
|
||||
result = h2.newVNode()
|
||||
of ArticleType.headerThree:
|
||||
result = h3.newVNode()
|
||||
of ArticleType.orderedListItem:
|
||||
result = li.newVNode()
|
||||
of ArticleType.unorderedListItem:
|
||||
result = li.newVNode()
|
||||
else:
|
||||
result = p.newVNode()
|
||||
|
||||
# Assume the style applies for the entire paragraph
|
||||
for styleRange in articleParagraph.inlineStyleRanges:
|
||||
case styleRange.style
|
||||
of ArticleStyle.bold:
|
||||
result.setAttr("style", "font-weight:bold")
|
||||
of ArticleStyle.italic:
|
||||
result.setAttr("style", "font-style:italic")
|
||||
of ArticleStyle.strikethrough:
|
||||
result.setAttr("style", "text-decoration:line-through")
|
||||
else: discard
|
||||
|
||||
var last = 0
|
||||
for er in articleParagraph.entityRanges:
|
||||
# prevent karax from inserting whitespaces to fix wrapping
|
||||
result.add text ""
|
||||
|
||||
# flush remaining text
|
||||
if er.offset > last:
|
||||
result.add verbatim text.runeSubStr(last, er.offset - last).replaceHashtagsAndMentions
|
||||
|
||||
if articleParagraph.baseType == ArticleType.atomic:
|
||||
let er = articleParagraph.entityRanges[0]
|
||||
let entity = article.entities[er.key]
|
||||
|
||||
case entity.entityType
|
||||
of ArticleEntityType.link:
|
||||
let link = buildHtml(a(href=entity.url)):
|
||||
text text.runeSubStr(er.offset, er.length)
|
||||
result.add link
|
||||
of ArticleEntityType.media:
|
||||
for id in entity.mediaIds:
|
||||
let media = article.media.getOrDefault(id)
|
||||
|
@ -71,27 +34,73 @@ proc renderNoteParagraph(articleParagraph: ArticleParagraph; article: Article; t
|
|||
of ArticleMediaType.image:
|
||||
let image = buildHtml(span(class="image")):
|
||||
img(src=media.url.getSmallPic, alt="")
|
||||
result.add image
|
||||
result = image
|
||||
of ArticleMediaType.gif:
|
||||
let video = buildHtml(span(class="image")):
|
||||
video(src=media.url.getVidUrl, controls="", autoplay="")
|
||||
result.add video
|
||||
result = video
|
||||
else: discard
|
||||
of ArticleEntityType.twemoji:
|
||||
let url = entity.twemoji.getSmallPic
|
||||
let emoji = buildHtml(img(class="twemoji", src=url, alt=""))
|
||||
result.add emoji
|
||||
of ArticleEntityType.tweet:
|
||||
let tweet = tweets.getOrDefault(entity.tweetId.parseInt, nil)
|
||||
if tweet == nil: discard
|
||||
result.add renderTweet(tweet, prefs, path, mainTweet=true)
|
||||
result = renderTweet(tweet, prefs, path, mainTweet=true)
|
||||
else: discard
|
||||
else:
|
||||
let text = articleParagraph.text
|
||||
|
||||
last = er.offset + er.length
|
||||
|
||||
# flush remaining text
|
||||
if last < text.len:
|
||||
result.add verbatim text.runeSubStr(last).replaceHashtagsAndMentions
|
||||
case articleParagraph.baseType
|
||||
of ArticleType.headerOne:
|
||||
result = h1.newVNode()
|
||||
of ArticleType.headerTwo:
|
||||
result = h2.newVNode()
|
||||
of ArticleType.headerThree:
|
||||
result = h3.newVNode()
|
||||
of ArticleType.orderedListItem:
|
||||
result = li.newVNode()
|
||||
of ArticleType.unorderedListItem:
|
||||
result = li.newVNode()
|
||||
of ArticleType.atomic:
|
||||
result = nil
|
||||
else:
|
||||
result = p.newVNode()
|
||||
|
||||
# Assume the style applies for the entire paragraph
|
||||
for styleRange in articleParagraph.inlineStyleRanges:
|
||||
case styleRange.style
|
||||
of ArticleStyle.bold:
|
||||
result.setAttr("style", "font-weight:bold")
|
||||
of ArticleStyle.italic:
|
||||
result.setAttr("style", "font-style:italic")
|
||||
of ArticleStyle.strikethrough:
|
||||
result.setAttr("style", "text-decoration:line-through")
|
||||
else: discard
|
||||
|
||||
var last = 0
|
||||
for er in articleParagraph.entityRanges:
|
||||
# prevent karax from inserting whitespaces to fix wrapping
|
||||
result.add text ""
|
||||
|
||||
# flush remaining text
|
||||
if er.offset > last:
|
||||
result.add verbatim text.runeSubStr(last, er.offset - last).replaceHashtagsAndMentions
|
||||
|
||||
let entity = article.entities[er.key]
|
||||
case entity.entityType
|
||||
of ArticleEntityType.link:
|
||||
let link = buildHtml(a(href=entity.url)):
|
||||
text text.runeSubStr(er.offset, er.length)
|
||||
result.add link
|
||||
of ArticleEntityType.twemoji:
|
||||
let url = entity.twemoji.getSmallPic
|
||||
let emoji = buildHtml(img(class="twemoji", src=url, alt=""))
|
||||
result.add emoji
|
||||
else: discard
|
||||
|
||||
last = er.offset + er.length
|
||||
|
||||
# flush remaining text
|
||||
if last < text.len:
|
||||
result.add verbatim text.runeSubStr(last).replaceHashtagsAndMentions
|
||||
|
||||
proc renderNote*(article: Article; tweets: Table[int64, Tweet]; path: string; prefs: Prefs): VNode =
|
||||
let cover = getSmallPic(article.coverImage)
|
||||
|
|
Loading…
Reference in New Issue