diff --git a/app/javascript/styles/mastodon/rich_text.scss b/app/javascript/styles/mastodon/rich_text.scss index c77c23bc4..5bab6e13f 100644 --- a/app/javascript/styles/mastodon/rich_text.scss +++ b/app/javascript/styles/mastodon/rich_text.scss @@ -54,6 +54,32 @@ ol { list-style-type: decimal; } + + h1 { + font-size: 1.5em; + font-weight: 700; + margin: 1em 0; + } + + h2 { + font-size: 1.25em; + font-weight: 700; + margin: 1em 0; + } + + h3 { + font-size: 1.125em; + font-weight: 700; + margin: 1em 0; + } + + h4, + h5, + h6 { + font-size: 1em; + font-weight: 700; + margin: 1em 0; + } } .reply-indicator__content { diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index d5497dbdd..a4cbee40f 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -78,8 +78,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity @silenced_account_ids = [] @params = {} - process_inline_images if @object['content'].present? && @object['type'] == 'Article' process_status_params + process_inline_images if @object['content'].present? && @object['type'] == 'Article' process_tags process_audience @@ -117,7 +117,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity account: @account, text: converted_object_type? ? converted_text : (@status_parser.text || ''), language: @status_parser.language, - spoiler_text: converted_object_type? ? '' : (@status_parser.spoiler_text || (@object['type'] == 'Article' && text_from_name) || ''), + spoiler_text: converted_object_type? ? '' : ((@object['type'] == 'Article' && text_from_name) || @status_parser.spoiler_text || ''), created_at: @status_parser.created_at, edited_at: @status_parser.edited_at && @status_parser.edited_at != @status_parser.created_at ? @status_parser.edited_at : nil, override_timestamps: @options[:override_timestamps], @@ -132,14 +132,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity } end - class Handler < ::Ox::Sax - attr_reader :srcs, :alts + class TextHandler < ::Ox::Sax + attr_reader :srcs, :alts, :original_srcs - def initialize(_block) + def initialize super @stack = [] @srcs = [] @alts = {} + @original_srcs = [] end def start_element(element_name) @@ -148,8 +149,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity def end_element(_element_name) self_name, self_attributes = @stack[-1] + # Create a list of image srcs and their alt text if self_name == :img && !self_attributes[:src].nil? @srcs << self_attributes[:src] + @original_srcs << self_attributes[:src].clone @alts[self_attributes[:src]] = self_attributes[:alt] end @stack.pop @@ -163,11 +166,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end def process_inline_images - proc = proc { |name| Rails.logger.debug name } - handler = Handler.new(proc) + handler = TextHandler.new Ox.sax_parse(handler, @object['content']) handler.srcs.each do |src| - # Handle images where the src is formatted as "/foo/bar.png" + # Handle images where the src is formatted as "/foo/bar.biz" # we assume that the `url` field is populated which lets us infer # the protocol and domain of the _original_ article, as though # we were looking at it via a web browser @@ -176,11 +178,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity src = site + src end + # if media is set to reject from this domain, replace the src with an empty string if skip_download? @object['content'].gsub!(src, '') next end + # Create a local proxy media file for each image in the post + # TODO: what about