diff options
author | pdp8 <pdp8@pdp8.info> | 2023-12-22 17:41:49 +0100 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-12-22 17:41:49 +0100 |
commit | 17fe7f0d25bc99285ddc3dbc153f1f3af9dca335 (patch) | |
tree | a660f2748a73f7e1b521dbf4a72c4f5d9929a5ae /create.rb | |
parent | 88518c5a4fa4fa9d841bb0d1c8add9fa2234530c (diff) |
create.rb: parse plain text
Diffstat (limited to 'create.rb')
-rw-r--r-- | create.rb | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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 = /^<!*--/ post '/create' do protected! @@ -19,10 +19,6 @@ post '/create' do request.body.read.each_line do |line| line.chomp! case line - when /^<!--$/ - next - when /^-->$/ - 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" + "<p>\n" else # create links - # single quotes in html invalidate digest, reason unknown - line.split(/\s+/).each do |word| - word = word.gsub('<p>', '').gsub('</p>', '') + 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 } + "<a href=\"#{tag_url}\">#{word}</a>" when MENTION_REGEXP actor = actor(word) tag << { @@ -63,9 +60,13 @@ post '/create' do 'href' => actor, 'name' => word } + to << actor + "<a href=\"#{actor}\">#{word}</a>" + 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 |