Skip to content

Commit d9ddc60

Browse files
committed
changes
1 parent 93da7da commit d9ddc60

9 files changed

Lines changed: 260 additions & 26 deletions

File tree

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ capability.
3030
- [x] Realtime website preview
3131
- [ ] Git manager
3232
- [ ] DevTools
33-
- [ ] Parse HTML layout from page
33+
- [x] Parse HTML layout from page
3434
- [ ] Extract JavaScript from HTML
3535
- [ ] Extract CSS from HTML
3636
- [ ] Code editor (SoraEditor)
3737
- [ ] Tree sitter
3838
- [x] Syntax highlight
39+
- [ ] JavaScript LSP
3940
- [ ] Code format
4041
- [ ] JavaScript
4142
- [ ] HTML
4243
- [ ] CSS
43-
- [ ] Language Servers
44-
- [ ] JavaScript
45-
- [ ] CSS
46-
- [ ] HTML
4744

4845
## 🤝 Contributing
4946

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ allprojects {
1616
multidex = "2.0.1"
1717
preference = "1.2.1"
1818
closure_compiler = "v20230206"
19-
jsoup = "1.17.2"
19+
jsoup = "1.21.1"
2020
swiperefreshlayout = "1.1.0"
2121
recyclerview = "1.3.2"
22+
lsp4j = "0.24.0"
2223

2324
mCompileSDK = 36
2425
mMinSDK = 26
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
[
2+
{
3+
"prefix": "html5",
4+
"description": "HTML5 document structure",
5+
"body": [
6+
"<!DOCTYPE html>",
7+
"<html lang=\"en\">",
8+
"<head>",
9+
" <meta charset=\"UTF-8\">",
10+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
11+
" <title>Document</title>",
12+
"</head>",
13+
"<body>",
14+
" $0",
15+
"</body>",
16+
"</html>"
17+
]
18+
},
19+
{
20+
"prefix": "div",
21+
"description": "Div element",
22+
"body": [
23+
"<div$1>$0</div>"
24+
]
25+
},
26+
{
27+
"prefix": "a",
28+
"description": "Anchor element",
29+
"body": [
30+
"<a href=\"$1\">$0</a>"
31+
]
32+
},
33+
{
34+
"prefix": "img",
35+
"description": "Image element",
36+
"body": [
37+
"<img src=\"$1\" alt=\"$2\">$0"
38+
]
39+
},
40+
{
41+
"prefix": "ul",
42+
"description": "Unordered list",
43+
"body": [
44+
"<ul>",
45+
" <li>$1</li>",
46+
" <li>$2</li>",
47+
" $0",
48+
"</ul>"
49+
]
50+
},
51+
{
52+
"prefix": "table",
53+
"description": "HTML table",
54+
"body": [
55+
"<table>",
56+
" <thead>",
57+
" <tr>",
58+
" <th>$1</th>",
59+
" <th>$2</th>",
60+
" </tr>",
61+
" </thead>",
62+
" <tbody>",
63+
" <tr>",
64+
" <td>$3</td>",
65+
" <td>$4</td>",
66+
" </tr>",
67+
" </tbody>",
68+
"</table>",
69+
"$0"
70+
]
71+
},
72+
{
73+
"prefix": "form",
74+
"description": "HTML form",
75+
"body": [
76+
"<form action=\"$1\" method=\"$2\">",
77+
" <label for=\"$3\">$4</label>",
78+
" <input type=\"text\" id=\"$3\" name=\"$3\">",
79+
" $0",
80+
" <button type=\"submit\">Submit</button>",
81+
"</form>"
82+
]
83+
},
84+
{
85+
"prefix": "input",
86+
"description": "Input element",
87+
"body": [
88+
"<input type=\"$1\" name=\"$2\" id=\"$2\"$3>$0"
89+
]
90+
},
91+
{
92+
"prefix": "button",
93+
"description": "Button element",
94+
"body": [
95+
"<button type=\"$1\">$0</button>"
96+
]
97+
},
98+
{
99+
"prefix": "meta",
100+
"description": "Meta element",
101+
"body": [
102+
"<meta name=\"$1\" content=\"$2\">$0"
103+
]
104+
}
105+
]

main/src/main/java/org/xedox/webaide/AppCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.xedox.utils.FileX;
1212
import org.xedox.utils.dialog.DialogBuilder;
1313
import org.xedox.utils.dialog.NeoAlertDialogBuilder;
14-
import org.xedox.webaide.editor.sora.SoraEditorManager;
14+
import org.xedox.utils.sora.SoraEditorManager;
1515
import static androidx.appcompat.app.AppCompatDelegate.*;
1616

1717
public class AppCore extends MultiDexApplication {

main/src/main/java/org/xedox/webaide/devtools/SourceFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void updateHtml(String newHtml) {
7878
this.html = newHtml;
7979
if (htmlFragment != null && htmlFragment.getEditor() != null) {
8080
htmlFragment.getEditor().setText(html);
81+
// scriptsFragment.setItems(webManager.extractJsScripts(html));
8182
}
8283
}
8384

main/src/main/java/org/xedox/webaide/devtools/WebManager.java

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WebManager {
1818
public void download(String url, OnDownloadListener downloadListener) throws IOException {
1919
HttpsURLConnection connection = null;
2020
BufferedReader reader = null;
21-
21+
2222
try {
2323
URL urlObj = new URL(url);
2424
connection = (HttpsURLConnection) urlObj.openConnection();
@@ -35,24 +35,24 @@ public void download(String url, OnDownloadListener downloadListener) throws IOE
3535

3636
int contentLength = connection.getContentLength();
3737
downloadListener.onDownloadStart(contentLength);
38-
38+
3939
StringBuilder content = new StringBuilder();
4040
int totalRead = 0;
41-
41+
4242
try (InputStream is = connection.getInputStream();
43-
InputStreamReader isr = new InputStreamReader(is, charset);
44-
BufferedReader br = new BufferedReader(isr)) {
45-
43+
InputStreamReader isr = new InputStreamReader(is, charset);
44+
BufferedReader br = new BufferedReader(isr)) {
45+
4646
char[] buffer = new char[8192];
4747
int bytesRead;
48-
48+
4949
while ((bytesRead = br.read(buffer)) != -1) {
5050
content.append(buffer, 0, bytesRead);
5151
totalRead += bytesRead;
5252
downloadListener.onDownload(totalRead, contentLength);
5353
}
5454
}
55-
55+
5656
downloadListener.onDownloadFinished(content.toString());
5757
} catch (IOException e) {
5858
if (downloadListener != null) {
@@ -61,7 +61,10 @@ public void download(String url, OnDownloadListener downloadListener) throws IOE
6161
throw e;
6262
} finally {
6363
if (reader != null) {
64-
try { reader.close(); } catch (IOException ignored) {}
64+
try {
65+
reader.close();
66+
} catch (IOException ignored) {
67+
}
6568
}
6669
if (connection != null) {
6770
connection.disconnect();
@@ -71,13 +74,26 @@ public void download(String url, OnDownloadListener downloadListener) throws IOE
7174

7275
public List<String> extractJsScripts(String html) {
7376
List<String> scripts = new ArrayList<>();
74-
Matcher matcher = Pattern.compile("<script\\b[^>]*>(.*?)</script>",
75-
Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(html);
77+
Matcher matcher =
78+
Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
79+
.matcher(html);
7680

7781
while (matcher.find()) {
78-
String scriptContent = matcher.group(1)
79-
.replaceAll("<!\\[CDATA\\[|\\]\\]>", "")
80-
.trim();
82+
String scriptContent = matcher.group(1).trim();
83+
if (!scriptContent.isEmpty()) {
84+
scripts.add(scriptContent);
85+
}
86+
}
87+
return scripts;
88+
}
89+
public List<String> extractJsScriptLinks(String html) {
90+
List<String> scripts = new ArrayList<>();
91+
Matcher matcher =
92+
Pattern.compile("<script src=\"(.*)\">[\\s]+</script>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
93+
.matcher(html);
94+
95+
while (matcher.find()) {
96+
String scriptContent = matcher.group(1).trim();
8197
if (!scriptContent.isEmpty()) {
8298
scripts.add(scriptContent);
8399
}
@@ -87,10 +103,13 @@ public List<String> extractJsScripts(String html) {
87103

88104
public interface OnDownloadListener {
89105
void onDownloadStart(int pageLength);
106+
90107
void onDownload(int downloaded, int pageLength);
108+
91109
void onDownloadFinished(String downloaded);
110+
92111
default void onDownloadError(IOException e) {
93112
e.printStackTrace();
94113
}
95114
}
96-
}
115+
}

main/src/main/res/layout/fragment_source.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<com.google.android.material.tabs.TabLayout
99
android:id="@+id/tab_layout"
10-
android:layout_height="wrap_content"
10+
android:layout_height="30dp"
1111
android:layout_width="match_parent"
1212
app:tabMode="fixed"
1313
app:tabGravity="fill">

utils/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdk mMinSDK
1111
targetSdk mTargetSDK
12-
versionCode 4
13-
versionName "0.0.4a"
12+
versionCode 5
13+
versionName "0.0.5a"
1414
multiDexEnabled true
1515
}
1616

@@ -22,6 +22,7 @@ android {
2222
}
2323

2424
compileOptions {
25+
coreLibraryDesugaringEnabled true
2526
sourceCompatibility JavaVersion.VERSION_17
2627
targetCompatibility JavaVersion.VERSION_17
2728
}
@@ -30,11 +31,18 @@ android {
3031
dependencies {
3132
api "androidx.appcompat:appcompat:$app_compat"
3233
api "androidx.preference:preference:$preference"
33-
api "org.eclipse.jgit:org.eclipse.jgit:$jgit"
3434
api "com.google.android.material:material:$material"
3535
api "io.github.Rosemoe.sora-editor:editor"
3636
api "io.github.Rosemoe.sora-editor:language-textmate"
37+
api "io.github.Rosemoe.sora-editor:editor-lsp"
38+
api "io.github.Rosemoe.sora-editor:tree-sitter"
3739
api platform("io.github.Rosemoe.sora-editor:bom:$sora_editor")
40+
api "com.google.code.gson:gson:$gson"
41+
42+
api("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4j")
43+
api("org.jsoup:jsoup:$jsoup")
44+
3845
implementation "io.noties.markwon:core:$markwonVersion"
3946
implementation("net.lingala.zip4j:zip4j:$zip4j")
47+
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugar_jdk_libs"
4048
}

0 commit comments

Comments
 (0)