Compare commits

...

3 commits

Author SHA1 Message Date
Alexander Olofsson
7458599ac2 Merge branch 'master' of git.sagaaboutyou.net:ace/fic_tracker 2024-12-17 15:58:30 +01:00
Alexander Olofsson
2a2a916ac1
Allow more text mutation for safe HTML 2024-12-17 15:57:59 +01:00
Alexander Olofsson
2256adae26
Improve story handling on CLI 2024-12-10 09:18:13 +01:00
2 changed files with 55 additions and 8 deletions

View file

@ -57,19 +57,48 @@ class FicTracker::Cli::Story < Thor
end
end
desc 'update STORY...', 'Force-update the listed stories'
def update(*stories)
setup!
stories.each do |story|
puts "Updating #{story} ..."
bend = FicTracker::Backends.find_backend story
if bend.nil?
puts " Can't update, no available backends."
next
end
bend = FicTracker::Backends.get(bend)
slug = story
slug = bend.parse_slug(story) if bend.respond_to? :parse_slug
story = FicTracker::Models::Story.find(backend_name: bend.name, slug:)
unless story
puts " Not tracking, skipping."
next
end
before = story.etag
story.refresh_metadata!
story.refresh_content!
render_story! story if story.etag != before
end
end
desc 'del STORY...', 'Remove stories from tracker'
def del(*stories)
setup!
stories.each do |story|
if story.include? '/'
backend, slug = story.split '/'
backend = nil if backend == '*'
backend_name, slug = story.split '/'
backend_name = nil if backend_name == '*'
else
slug = story
end
search = {
backend:,
backend_name:,
slug:
}.compact
found = FicTracker::Models::Story.where(**search)

View file

@ -8,19 +8,23 @@ module Kramdown::Converter
class SafeHtml < Base
def initialize(root, options)
super
@options[:remove_block_html_tags] = true
@options[:remove_span_html_tags] = false
@options[:template] = 'string://<%= Html.convert(@body).first %>'
end
SUPERFLUOUS_TAGS = %w[align class justify]
ALLOWED_ATTRS = %w[alt dir hidden inert lang title translate]
def convert(el)
real_el, el = el, el.value if el.type == :footnote
# Strip out unnecessary HTML tags
SUPERFLUOUS_TAGS.each { |tag| el.attr.delete tag if el.attr.key? tag }
# Strip out superfluous and invalid HTML 5 tags
style = el.attr['style'] || ""
style += ";text-align:#{el.attr['align']}" if el.attr.key? 'align'
style = strip_style(style) if style.include? ':'
el.attr.delete_if { |key, _| !ALLOWED_ATTRS.include?(key) }
el.attr['style'] = style if style.include? ':'
children = el.children.dup
index = 0
@ -43,5 +47,19 @@ module Kramdown::Converter
real_el || el
end
private
ALLOWED_STYLE_ASSIGNMENTS = %w[font-size font-style font-weight text-align]
def strip_style(style)
parts = style.split(';').select { |p| p.include? ':' }.to_h do |assign|
parts = assign.split(':')
[parts.first.strip, parts.last.strip]
end
parts.delete_if { |key, _| !ALLOWED_STYLE_ASSIGNMENTS.include?(key) }
parts.map { |key, val| "#{key}:#{val}" }.join(';')
end
end
end