book-content/hytrans/ex.md

72 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## 一些奇怪的套娃
#### A
(民间)树状 hytrans 数据解决方案
```hytrans
key
| key
| | key
| | | key
| | | | value
```
上面的数据该如何取出呢&?java
```java
String value = HyTransParser.parse(
HyTransParser.parse(
HyTransParser.parse(
HyTransParser.parse(stringData).get("key").value()
).get("key").value()
).get("key").value()
).get("key").value();
```
#### 彩蛋二号
...要说硬编码...好像不是硬编码...要说没有...好像确实是硬编码
```html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.hytrans-data {
display: none;
}
</style>
<body>
<h1 class="hytrans">page.title</h1>
<p class="hytrans">page.paraph-text</p>
<pre class="hytrans-data" hytrans-lang="en_us">
%1.0
$ignore-fist-space
html.title
| Demo Page
page.title
| Demo title
page.paraph-text
| Demo Paraph and some text.
</pre>
<script src="https://srv.sukazyo.cc/assets/js/hytrans/hytrans-parser.js?v=1.0"></script>
<script>
var transdata = HyTransParser.parse(document.getElementsByClassName("hytrans-data")[0].innerHTML);
document.title = transdata.get("html.title").value;
for (var node of document.getElementsByClassName("hytrans")) {
node.innerHTML = transdata.get(node.innerHTML).value;
}
</script>
</body>
</html>
```