Skip to content
Permalink
Browse files

update readme

Signed-off-by: 天空Blond <hurui200320@skyblond.info>
  • Loading branch information...
hurui200320 committed Mar 29, 2019
1 parent e5200cf commit d99b14f7732077339902db1ca351ce329432b39d
Showing with 50 additions and 12 deletions.
  1. +25 −6 README.md
  2. +25 −6 README_EN.md
@@ -113,12 +113,31 @@ Messages messages = new Messages();
messages.setTitle(String.join("",raw.get(POST_TITLE_FIELD)));
String[] body = String.join("",raw.get(POST_CONTENT_FIELD)).split("\n");
StringBuilder sb = new StringBuilder();
boolean isRaw = false;
for(String s : body){
if(s.startsWith("#!&$>") && s.length() > 5){
sb.append(s.substring(5));
}else {
sb.append("<p>" + s + "</p>\n");
}
if(!isRaw && s.startsWith("#!&$>") && s.length() > 5){
sb.append(s.substring(5));
}else if(isRaw || s.startsWith("#!&$<")){
isRaw = true;
if(s.startsWith("#!&$<"))
sb.append(s.substring(5) + "\n");
else if(s.contains("&!>")){
sb.append(s.split("&!>")[0] + "\n");
isRaw = false;
}else
sb.append(s + "\n");
}else {
if(s.equals(null) || s.equals(""))
sb.append("<br>");
else{
s = s.replace("&", "&amp;");
s = s.replace(" ","&nbsp;"); // html Escape characters
s = s.replace("<", "&lt;");
s = s.replace(">", "&gt;");
s = s.replace("\"", "&quot;");
sb.append("<p>" + s + "</p>\n");
}
}
}
messages.setContent(sb.toString());
@@ -139,7 +158,7 @@ ctx.header("content-type","text/html; charset=UTF-8");
ctx.result(String.join("\n", Files.readAllLines(PropertiesUtils.getProperties().getSucceedTheme())).replace("{{% code %}}", result));
```

消息标题保留原样,针对每一行内容都翻译成`HTML`的段落。如果以特定的`#!&$>`开头,则不进行翻译。完成后对消息进行储存,储存成功后将得到一个对应的`ID`,此时服务器返回状态码`201`,同时引用模板将得到的`ID`显示给用户。默认情况下模板是与程序同目录下的`createSucceed.html`,其中的占位符`{{% code %}}`替换成得到的`ID`
消息标题保留原样,针对每一行内容都翻译成`HTML`的段落并进行转义。如果以特定的`#!&$>`开头,则不进行翻译。如果一行以`#!&$<`开头,则表示一段内容不进行翻译,则类似C语言中`/**/`这样的段落注释,但要求上述字符串前不能有多于字符。段落保留以`&!>`结束,该字符串可在行内的任意位置出现,一行内其后的内容将被丢弃。上述操作完成后对消息进行储存,储存成功后将得到一个对应的`ID`,此时服务器返回状态码`201`,同时引用模板将得到的`ID`显示给用户。默认情况下模板是与程序同目录下的`createSucceed.html`,其中的占位符`{{% code %}}`替换成得到的`ID`

#### `/*` `GET`

@@ -115,12 +115,31 @@ Messages messages = new Messages();
messages.setTitle(String.join("",raw.get(POST_TITLE_FIELD)));
String[] body = String.join("",raw.get(POST_CONTENT_FIELD)).split("\n");
StringBuilder sb = new StringBuilder();
boolean isRaw = false;
for(String s : body){
if(s.startsWith("#!&$>") && s.length() > 5){
sb.append(s.substring(5));
}else {
sb.append("<p>" + s + "</p>\n");
}
if(!isRaw && s.startsWith("#!&$>") && s.length() > 5){
sb.append(s.substring(5));
}else if(isRaw || s.startsWith("#!&$<")){
isRaw = true;
if(s.startsWith("#!&$<"))
sb.append(s.substring(5) + "\n");
else if(s.contains("&!>")){
sb.append(s.split("&!>")[0] + "\n");
isRaw = false;
}else
sb.append(s + "\n");
}else {
if(s.equals(null) || s.equals(""))
sb.append("<br>");
else{
s = s.replace("&", "&amp;");
s = s.replace(" ","&nbsp;"); // html Escape characters
s = s.replace("<", "&lt;");
s = s.replace(">", "&gt;");
s = s.replace("\"", "&quot;");
sb.append("<p>" + s + "</p>\n");
}
}
}
messages.setContent(sb.toString());
@@ -141,7 +160,7 @@ ctx.header("content-type","text/html; charset=UTF-8");
ctx.result(String.join("\n", Files.readAllLines(PropertiesUtils.getProperties().getSucceedTheme())).replace("{{% code %}}", result));
```

The title of the message won't change. Every line of the content will be translated in `HTML` paragraph, unless it start with special characters `#!&$>`. Then store it and return a corresponding `ID`. At this time, server return status code `201` and render the web page according to the template. In default it's `createSucceed.html`. The placeholder `{{% code %}}` is the `ID`.
The title won't change. Every line will be translated into HTML-style paragraph and replace html characters(like `& < > "`), unless it starts with `#!&$>`. For multiple lines, starting with `#!&$<` in a line means there is a paragraph of content should be reserved, just like comments `/**/` in C or Java. You have to put that string at the head of line, and end it with `&!>` in anywhere. Noticed, the content after `&!>` will be discarded. Then the message will be stored and server returns a corresponding `ID`. At this time, server return status code `201` and render the web page according to the template. In default it's `createSucceed.html`. The placeholder `{{% code %}}` is the `ID`.

#### `/*` `GET`

0 comments on commit d99b14f

Please sign in to comment.
You can’t perform that action at this time.