1

I am using SDcv, Collins Cobuild 5 is it's dictionary, which output html, like:

    # czxyl @ archlinux in ~/Dropbox [12:57:27] C:16
$ sdcv hello               
Found 7 items, similar to hello.
-->CMU American English spelling
-->hello

[hə'ləu]

-->dictd_www.dict.org_gcide
-->Hello

Hello \Hel*lo"\, interj. & n.
   An exclamation used as a greeting, to call attention, as an
   exclamation of surprise, or to encourage one. This variant of
   {Halloo} and {Holloo} has become the dominant form. In the
   United States, it is the most common greeting used in
   answering a telephone.
   [1913 Webster +PJC]


-->WordNet
-->hello

hello
     n : an expression of greeting; "every morning they exchanged
         polite hellos" [syn: {hullo}, {hi}, {howdy}, {how-do-you-do}]

-->Webster's Revised Unabridged Dictionary (1913)
-->Hello

Hello \Hel*lo"\, interj. & n.
   See {Halloo}.

-->牛津现代英汉双解词典
-->hello

= hallo.

-->Longman Dictionary of Contemporary English
-->hello

S1   interjection, n  also  hallo, hullo BrE  [C]   [Date: 1800-1900; Origin: hollo a shout to call attention  (16-19 centuries)]//
  1 used as a greeting when you see or meet someone:  --Hello, John! How are you?//  --Stanley, come and say hello to your nephew.//  --Well, hello there ! I haven't seen you for ages.//
  2 used when answering the telephone or starting a telephone conversation:  --Hello - may I speak to Anne?//
  3 used when calling to get someone's attention:  --Hello! Is there anybody home?//
  4 used when you think someone is not acting sensibly or has said something stupid:  --You didn't remember her birthday? Hello!//
  5  BrE used to show that you are surprised or confused by something:  --Hello! What's happened here?//
  6  say hello:  to have a quick conversation with someone//  --Promise you'll look in and say hello when you have time.//

-->Collins Cobuild 5
-->golden hello

<b>gold|en hel|lo</b> <b>(golden hellos)</b><br><FONT COLOR="#007000">[N-COUNT]</FONT><br>  A <b>golden hello</b> is a sum of money that a company offers to a person in order to persuade them to join the company. (BUSINESS)<br>  ● <font color="#004080"><i>Most people recognise the need to pay a golden hello to attract the best.</i></font><hr>

I hope to see:

enter image description here

EDIT:

Because the output contains both plain text and html code(Collins Cobuild 5 provides html output, others provide plain text, I want to render only html segments. My solution is redirecting the stdout to local markdown(if to local html file, plain texts will huddled together), then use pandoc render markdown to html, elink -dump local-html to stdout. Codes are in my own answer.

  • Kindly post your expected output with given input – Praveen Kumar BS Apr 15 '18 at 5:11
  • @PraveenKumarBS OK – 陳 力 Apr 15 '18 at 5:17
  • 3
    see lynx, links, elinks, or w3m – Patrick Apr 15 '18 at 5:52
  • @Partrick thanks. elinks can render local html file then output to stdout. but my request is render stdout file in the background then output to stdout. – 陳 力 Apr 15 '18 at 10:24
1

Use a text mode browser such as w3m or lynx. Strip off the non-HTML prefix, and tell the browser that this is HTML (lynx assumes it, but w3m doesn't, because this is an HTML snippet, not a full document). Tell the browser to dump to screen rather than show an interactive interface.

$ /usr/bin/sdcv counterpart | awk '/^</ {p=1} p' | w3m -T text/html -dump
◆ counter|part /k'aʊntə^rpɑː^rt/ (counterparts)
[N-COUNT] with supp, usu poss N
Someone's or something's counterpart is another person or thing that has a
similar function or position in a different place.
● The Foreign Secretary telephoned his Italian counterpart to protest.
$ /usr/bin/sdcv counterpart | awk '/^</ {p=1} p' | lynx -stdin -dump
   ◆ counter|part /k'aʊntə^rpɑː^rt/ (counterparts)
   [N-COUNT] with supp, usu poss N
   Someone's or something's counterpart is another person or thing that
   has a similar function or position in a different place.
   ● The Foreign Secretary telephoned his Italian counterpart to protest.
     __________________________________________________________________
  • I have updated my question, quite sorry :P – 陳 力 Apr 16 '18 at 5:07
0

I have solved the problem with pandoc and elinks: save output(stdout) as markdown file, then use pandoc render md to html file, render local html file with elink -dump finally. Below is my script:


#tt.sh
/usr/bin/sdcv $1 > /home/czxyl/Documents/firstlove.md
pandoc /home/czxyl/Documents/firstlove.md -o /home/czxyl/Documents/firstlove.html
elinks -dump /home/czxyl/Documents/firstlove.html
rm /home/czxyl/Documents/firstlove.html /home/czxyl/Documents/firstlove.md

alias def='. tt.sh'


# czxyl @ archlinux in ~ [0:22:34] 
$ def hello
   Found 7 items, similar to hello. –>CMU American English spelling –>hello

   [hə’ləu]

   –>dictd_www.dict.org_gcide –>Hello

   Hello lo“, interj. & n. An exclamation used as a greeting, to call
   attention, as an exclamation of surprise, or to encourage one. This
   variant of {Halloo} and {Holloo} has become the dominant form. In the
   United States, it is the most common greeting used in answering a
   telephone. [1913 Webster +PJC]

   –>WordNet –>hello

   hello n : an expression of greeting; “every morning they exchanged polite
   hellos” [syn: {hullo}, {hi}, {howdy}, {how-do-you-do}]

   –>Webster’s Revised Unabridged Dictionary (1913) –>Hello

   Hello lo“, interj. & n. See {Halloo}.

   –>牛津现代英汉双解词典 –>hello

   = hallo.

   –>Longman Dictionary of Contemporary English –>hello

   S1 interjection, n also hallo, hullo BrE [C] [Date: 1800-1900; Origin:
   hollo a shout to call attention (16-19 centuries)]// 1 used as a greeting
   when you see or meet someone: –Hello, John! How are you?// –Stanley, come
   and say hello to your nephew.// –Well, hello there ! I haven’t seen you
   for ages.// 2 used when answering the telephone or starting a telephone
   conversation: –Hello - may I speak to Anne?// 3 used when calling to get
   someone’s attention: –Hello! Is there anybody home?// 4 used when you
   think someone is not acting sensibly or has said something stupid: –You
   didn’t remember her birthday? Hello!// 5 BrE used to show that you are
   surprised or confused by something: –Hello! What’s happened here?// 6 say
   hello: to have a quick conversation with someone// –Promise you’ll look in
   and say hello when you have time.//

   –>Collins Cobuild 5 –>golden hello

   gold|en hel|lo (golden hellos)
   [N-COUNT]
   A golden hello is a sum of money that a company offers to a person in
   order to persuade them to join the company. (BUSINESS)
   ● Most people recognise the need to pay a golden hello to attract the
   best.

   ══════════════════════════════════════════════════════════════════════════

# czxyl @ archlinux in ~ [0:22:40] 
$ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.