about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/javascript/flavours/glitch/features/compose/components/options.js10
-rw-r--r--app/lib/bangtags.rb5
-rw-r--r--app/lib/formatter.rb7
-rw-r--r--app/models/status.rb2
-rw-r--r--app/serializers/activitypub/note_serializer.rb4
-rw-r--r--app/services/import_service.rb2
-rw-r--r--app/views/settings/preferences/show.html.haml2
-rw-r--r--app/workers/log_worker.rb2
8 files changed, 28 insertions, 6 deletions
diff --git a/app/javascript/flavours/glitch/features/compose/components/options.js b/app/javascript/flavours/glitch/features/compose/components/options.js
index 4203eb567..5782e8c04 100644
--- a/app/javascript/flavours/glitch/features/compose/components/options.js
+++ b/app/javascript/flavours/glitch/features/compose/components/options.js
@@ -77,6 +77,10 @@ const messages = defineMessages({
     defaultMessage: 'Markdown',
     id: 'compose.content-type.markdown',
   },
+  console: {
+    defaultMessage: 'Console',
+    id: 'compose.content-type.console',
+  },
   plain: {
     defaultMessage: 'Plain text',
     id: 'compose.content-type.plain',
@@ -258,6 +262,11 @@ class ComposerOptions extends ImmutablePureComponent {
         name: 'text/plain',
         text: <FormattedMessage {...messages.plain} />,
       },
+      console: {
+        icon: 'terminal',
+        name: 'text/console',
+        text: <FormattedMessage {...messages.console} />,
+      },
       html: {
         icon: 'code',
         name: 'text/html',
@@ -355,6 +364,7 @@ class ComposerOptions extends ImmutablePureComponent {
               contentTypeItems.xbbcode,
               contentTypeItems.html,
               contentTypeItems.plain,
+              contentTypeItems.console,
             ]}
             onChange={onChangeContentType}
             onModalClose={onModalClose}
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 290d2b294..acb83221e 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -504,6 +504,11 @@ class Bangtags
             'plain'       => 'text/plain',
             'plaintext'   => 'text/plain',
 
+            'c'           => 'text/console',
+            'console'     => 'text/console',
+            'terminal'    => 'text/console',
+            'monospace'   => 'text/console',
+
             'm'           => 'text/markdown',
             'md'          => 'text/markdown',
             'markdown'    => 'text/markdown',
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 524e09247..bbe123b54 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -229,6 +229,7 @@ class Formatter
     else
       html = simple_format(html, {}, sanitize: false)
       html = html.delete("\n")
+      html = format_console(html) if status.content_type == 'text/console'
     end
 
     unless status.footer.blank?
@@ -247,13 +248,17 @@ class Formatter
     html.html_safe # rubocop:disable Rails/OutputSafety
   end
 
+  def format_console(html)
+    "<pre><code>#{html}</code></pre>"
+  end
+
   def format_markdown(html)
     html = markdown_formatter.render(html)
   end
 
   def format_bbcode(html)
     html = bbcode_formatter(html)
-    html = html.gsub(/<hr>.*<\/hr>/im, '<hr />')
+    html.gsub(/<hr>.*<\/hr>/im, '<hr />')
   end
 
   def format_bbdown(html)
diff --git a/app/models/status.rb b/app/models/status.rb
index 16206ae5e..5fba7b38a 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -88,7 +88,7 @@ class Status < ApplicationRecord
   validates_with DisallowedHashtagsValidator
   validates :reblog, uniqueness: { scope: :account }, if: :reblog?
   validates :visibility, exclusion: { in: %w(direct limited) }, if: :reblog?
-  validates :content_type, inclusion: { in: %w(text/plain text/markdown text/x-bbcode text/x-bbcode+markdown text/html) }, allow_nil: true
+  validates :content_type, inclusion: { in: %w(text/plain text/console text/markdown text/x-bbcode text/x-bbcode+markdown text/html) }, allow_nil: true
 
   accepts_nested_attributes_for :poll
 
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index c4f1dac7f..56975ed80 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -40,7 +40,9 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
   end
 
   def source
-    { 'source' => object.proper.text, 'mediaType' => object.proper.content_type || 'text/plain' }
+    content_type = object.proper.content_type || 'text/plain'
+    content_type = 'text/plain+console' if content_type == 'text/console'
+    { 'source' => object.proper.text, 'mediaType' => content_type }
   end
 
   def content_map
diff --git a/app/services/import_service.rb b/app/services/import_service.rb
index 248178e8c..c4bc7d74c 100644
--- a/app/services/import_service.rb
+++ b/app/services/import_service.rb
@@ -7,7 +7,7 @@ class ImportService < BaseService
   include JsonLdHelper
 
   ROWS_PROCESSING_LIMIT = 20_000
-  CONTENT_TYPES = %w(text/bbcode+markdown text/markdown text/bbcode text/html text/plain).freeze
+  CONTENT_TYPES = %w(text/bbcode+markdown text/markdown text/bbcode text/html text/plain text/console).freeze
   VISIBILITIES = [:public, :unlisted, :private, :direct, :limited].freeze
   IMPORT_STATUS_ATTRIBUTES = [
     'id',
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index 47c3d6915..99eac3abf 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -25,7 +25,7 @@
   .fields-group
     = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_floating_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), content_tag(:span, I18n.t("statuses.visibilities.#{visibility}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
 
-    = f.input :setting_default_content_type, collection: ['text/x-bbcode+markdown', 'text/markdown', 'text/x-bbcode', 'text/html', 'text/plain'], wrapper: :with_label, include_blank: false, label_method: lambda { |item| safe_join([t("simple_form.labels.defaults.setting_default_content_type_#{item.split('/')[1].gsub(/[+-]/, '_')}"), content_tag(:span, t("simple_form.hints.defaults.setting_default_content_type_#{item.split('/')[1].gsub(/[+-]/, '_')}_html"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
+    = f.input :setting_default_content_type, collection: ['text/x-bbcode+markdown', 'text/markdown', 'text/x-bbcode', 'text/html', 'text/plain', 'text/console'], wrapper: :with_label, include_blank: false, label_method: lambda { |item| safe_join([t("simple_form.labels.defaults.setting_default_content_type_#{item.split('/')[1].gsub(/[+-]/, '_')}"), content_tag(:span, t("simple_form.hints.defaults.setting_default_content_type_#{item.split('/')[1].gsub(/[+-]/, '_')}_html"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
 
     = f.input :setting_default_local, as: :boolean, wrapper: :with_label
     = f.input :setting_always_local, as: :boolean, wrapper: :with_label
diff --git a/app/workers/log_worker.rb b/app/workers/log_worker.rb
index d3d22c88e..f56becd66 100644
--- a/app/workers/log_worker.rb
+++ b/app/workers/log_worker.rb
@@ -22,7 +22,7 @@ class LogWorker
       tags: [tag],
       visibility: :unlisted,
       local_only: true,
-      content_type: 'text/plain',
+      content_type: 'text/console',
       language: 'en',
       nocrawl: true,
       nomentions: true,