slack icon indicating copy to clipboard operation
slack copied to clipboard

Unescape to get plain text

Open dominhtri1995 opened this issue 5 years ago • 3 comments

Is there any methods to achieve this as in https://github.com/slack-ruby/slack-ruby-client

We basically get the plain text from html

`Slack::Messages::Formatting.unescape('Hello & <world>'))

=> 'Hello & '

Slack::Messages::Formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?'))

=> 'Hey @bob, did you see my file?'

Slack::Messages::Formatting.unescape('Hey <@U02BEFY4U>'))

=> 'Hey @U02BEFY4U'

Slack::Messages::Formatting.unescape('This message contains a URL http://foo.com/'))

=> 'This message contains a URL http://foo.com/'

Slack::Messages::Formatting.unescape('So does this one: http://www.foo.com|www.foo.com'))

=> 'So does this one: www.foo.com'

Slack::Messages::Formatting.unescape('mailto:[email protected]|Bob'))

=> 'Bob'

Slack::Messages::Formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>'))

=> 'Hello @bob, say hi to @everyone in #general'

Slack::Messages::Formatting.unescape('Hello <@U123|bob> > file.txt'))

=> 'Hello @bob > file.txt'

Slack::Messages::Formatting.unescape('“hello”'))

=> '"hello"'

Slack::Messages::Formatting.unescape('‘hello’'))

=> "'hello'"`

dominhtri1995 avatar Jun 10 '19 15:06 dominhtri1995

despite some of those transforms being incorrect.... no currently not. though I do have a version lying around to get someone started if they wanted to do the work.

james-lawrence avatar Jun 22 '19 22:06 james-lawrence

@james-lawrence I'd be happy to give this a go, I guess :)

mzjp2 avatar Aug 29 '19 20:08 mzjp2

if you want code to get started, here is a custom lexer/parser I've written, its obviously very customized to my use case but the lexer is self contained and the parser should be easy to change for your uses: parsing-slack.zip

been using it for a year or so, so its fairly well tested. at a minimum the tests will be useful =)

james-lawrence avatar Aug 31 '19 11:08 james-lawrence