Files
simple-aircraft-manager-rails/app/helpers/markdown_helper.rb
T
rickyandClaude Opus 5.5 5876c07a1a Harden installs reachable from the internet without a proxy
- Refuse to start with a placeholder or short SECRET_KEY_BASE (under 32
  characters); warn and fail sam:doctor under 64. .env.example no longer
  ships a placeholder.
- First-run setup needs a one-time code printed only in the server log, so
  only whoever runs the server can create the admin account.
- AirTrail: the server resolves the address and connects to exactly that;
  never the server itself or link-local addresses (cloud metadata);
  private-network addresses only for admins or hosts in
  AIRTRAIL_ALLOWED_HOSTS.
- Host authorization when APP_HOST is set: APP_HOST, the APP_URL host,
  ALLOWED_HOSTS, localhost and IP addresses; /up exempt. A blocked name
  gets a short explanation instead of a blank 403.
- docker-compose.direct.yml: HTTPS without a proxy via Thruster's built-in
  Let's Encrypt (TLS_DOMAIN).
- Notes' Markdown no longer allows the unused class attribute.
- README, .env.example and the user guide updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 12:42:53 -05:00

30 lines
1.6 KiB
Ruby

# GitHub-flavored Markdown for notes. Raw HTML in the source is dropped and the
# output is sanitized again, so notes (some shown on public share links) can't
# inject markup. Single line breaks are kept, so plain-text notes written
# before Markdown support look the same as before.
module MarkdownHelper
OPTIONS = {
parse: { smart: true },
render: { hardbreaks: true, unsafe: false, escape: false },
extension: { strikethrough: true, tagfilter: true, table: true, autolink: true, tasklist: true, header_ids: nil, footnotes: false }
}.freeze
TAGS = %w[p br strong em del a ul ol li blockquote code pre h1 h2 h3 h4 h5 h6 hr table thead tbody tr th td input span].freeze
ATTRIBUTES = %w[href title type checked disabled align].freeze
def markdown(text)
return "".html_safe if text.blank?
html = Commonmarker.to_html(text.to_s, options: OPTIONS, plugins: { syntax_highlighter: nil })
html = sanitize(html, tags: TAGS, attributes: ATTRIBUTES)
# Links open in a new tab (notes often link to manuals and vendors).
html = html.gsub(/<a href=/, '<a target="_blank" rel="noopener nofollow" href=')
tag.div(html.html_safe, class: "markdown") # rubocop:disable Rails/OutputSafety -- sanitized above
end
# Plain-text excerpt for previews ("**Oil** leak at…" → "Oil leak at…").
def markdown_excerpt(text, length: 200)
return "" if text.blank?
html = Commonmarker.to_html(text.to_s, options: OPTIONS.merge(render: { hardbreaks: false, unsafe: false }), plugins: { syntax_highlighter: nil })
CGI.unescapeHTML(strip_tags(html.gsub(%r{</(p|li|h\d|tr|blockquote)>}, " "))).squish.truncate(length)
end
end