Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simple rendering of messages

With proper rendering of links and making <A> anchors from user (@)
and label (#) references in the message.
  • Loading branch information...
commit 7866469653cb57d9979dda5ceffe88c327348838 1 parent 7c0520d
@akoprow akoprow authored
Showing with 20 additions and 3 deletions.
  1. +3 −0  src/label.opa
  2. +14 −3 src/msg.opa
  3. +3 −0  src/user.opa
View
3  src/label.opa
@@ -12,4 +12,7 @@ Label = {{
mk_ref(label : string) : Label.ref =
@wrap(label)
+ to_anchor(label : Label.ref) : xhtml =
+ <A href="/label/{@unwrap(label)}">#{label}</>
+
}}
View
17 src/msg.opa
@@ -10,7 +10,7 @@ type Msg.t = private(string)
type Msg.segment =
{ text : string }
/ { label : Label.ref }
- / { url : Url.url }
+ / { url : Uri.uri }
/ { user : User.ref }
Msg = {{
@@ -18,7 +18,7 @@ Msg = {{
create(s : string) : Msg.t =
@wrap(s)
- parse(msg : Msg.t) : list(Msg.segment) =
+ @private parse(msg : Msg.t) : list(Msg.segment) =
word = parser
/* FIXME we probably want to extend the character set
below. */
@@ -26,9 +26,20 @@ Msg = {{
segment_parser = parser
| [@] user=word -> { user = User.mk_ref(user) }
| [#] label=word -> { label = Label.mk_ref(label) }
- | &"http://" url=UriParser.uri -> ~{ url }
+ | &"http://" url=Uri.uri_parser -> ~{ url }
| txt=((![@#] .)*) -> { text = Text.to_string(txt) }
msg_parser = parser res=segment_parser* -> res
Parser.parse(msg_parser, @unwrap(msg))
+ render(msg : Msg.t) : xhtml =
+ render_segment =
+ | ~{ text } -> <>{text}</>
+ | ~{ url } ->
+ url_string = Uri.to_string(url)
+ <A href={url_string}>{url_string}</>
+ | ~{ label } -> Label.to_anchor(label)
+ | ~{ user } -> User.to_anchor(user)
+ content = List.map(render_segment, parse(msg))
+ <div class="msg">{content}</>
+
}}
View
3  src/user.opa
@@ -12,4 +12,7 @@ User = {{
mk_ref(user : string) : User.ref =
@wrap(user)
+ to_anchor(user : User.ref) : xhtml =
+ <A href="/user/{@unwrap(user)}">@{user}</>
+
}}
Please sign in to comment.
Something went wrong with that request. Please try again.