From 17fe7f0d25bc99285ddc3dbc153f1f3af9dca335 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Fri, 22 Dec 2023 17:41:49 +0100 Subject: create.rb: parse plain text --- create.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'create.rb') diff --git a/create.rb b/create.rb index dc1daab..40bfbb8 100644 --- a/create.rb +++ b/create.rb @@ -1,10 +1,10 @@ TO_REGEXP = /^to:\s+/i +CC_REGEXP = /^cc:\s+/i REPLY_REGEXP = /^inreplyto:\s+/i ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} MENTION_REGEXP = /\A@\w+@\S+\Z/ HASHTAG_REGEXP = /\A#\w+\Z/ -# COMMENT_REGEXP = /^$/ - next when TO_REGEXP line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word @@ -40,14 +36,14 @@ post '/create' do url, description = line.sub(ATTACH_REGEXP, '').split(/\s+/, 2) attachment << { 'type' => 'Document', - 'mediaType' => media_type(url), + 'mediaType' => media_type(url), # TODO: query with curl HEAD 'url' => url, 'name' => description } + when "\n" + "

\n" else # create links - # single quotes in html invalidate digest, reason unknown - line.split(/\s+/).each do |word| - word = word.gsub('

', '').gsub('

', '') + content << line.split(/\s+/).collect do |word| case word when HASHTAG_REGEXP tag_url = File.join('https://social.pdp8.info', 'tags', word.sub('#', '')) @@ -56,6 +52,7 @@ post '/create' do 'href' => tag_url, 'name' => word } + "#{word}" when MENTION_REGEXP actor = actor(word) tag << { @@ -63,9 +60,13 @@ post '/create' do 'href' => actor, 'name' => word } + to << actor + "#{word}" + else + word end - end - content << line + end.join(' ') + # content << line end end @@ -89,9 +90,9 @@ post '/create' do object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? # p to - # jj object + jj object - create_activity 'Create', object, to + # create_activity 'Create', object, to 200 end -- cgit v1.2.3