Skip to content

Commit

Permalink
feat: 去除 html 标签
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed Jun 1, 2024
1 parent f8512ea commit 1f54e59
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"*.d.ts"
],
"scripts": {
"clean": "rimraf packages/*/node_modules --glob",
"run:core": "npm -C packages/core run start",
"core:build": "npm -C packages/core run build",
"shared:build": "npm -C packages/shared run build",
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/analyzer/AnalyzerHtml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { load } from 'cheerio'
import type { Analyzer } from './Analyzer'

/**
* 去除 html 标签
* @param {string} html
* @returns {string}
*/
function getHtmlString(html: string) {
return html.replaceAll(/<\/?(?:div|p|br|hr|h\d|article|b|dd|dl)[^>]*>/g, '\n')
}

export class AnalyzerHtml implements Analyzer {
_content!: string

Expand Down Expand Up @@ -28,7 +37,7 @@ export class AnalyzerHtml implements Analyzer {
case 'innerHtml':
return $.root().map((_, el) => $(el).html()).get().join('\n').trim() || ''
case 'html':
return $.html() || ''
return getHtmlString($.html()) || ''
}
if (lastRule)
return $(html || this._content).attr(lastRule)?.trim() || ''
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/analyzer/AnalyzerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class AnalyzerManager {
if (position < rule.length)
rs.push(rule.substring(position))

return rs
return rs.filter(e => e)
}

let temp: string | string[] = this._content
Expand Down
15 changes: 13 additions & 2 deletions packages/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
</a>
</p>

QQ 群: 50057637

## 功能

- [x] 本地小说阅读
- [x] txt格式
- [x] epub格式
- [x] txt 格式
- [x] epub 格式
- [x] 小说章节识别
- [x] 在线小说阅读
- [x] 自定义书源规则
Expand Down Expand Up @@ -90,6 +92,15 @@

![image](https://github.com/aooiuu/any-reader/assets/28108111/d4c1eb85-e90a-45e6-98b8-420992a216e5)

### 桌面端

[文档](https://aooiuu.github.io/any-reader/desktop/)

| - | - |
| :-------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: |
| ![image](https://github.com/aooiuu/any-reader/assets/28108111/bf5b9edf-8b1e-4db5-adfb-1b1300f57a4a) | ![image](https://github.com/aooiuu/any-reader/assets/28108111/3d001367-ff2d-4339-a617-0700b492f601) |
| ![image](https://github.com/aooiuu/any-reader/assets/28108111/1e8fcb4e-2ca5-49a9-ba7e-d5c7ac19856b) | ![image](https://github.com/aooiuu/any-reader/assets/28108111/a732f2ce-452e-4525-8059-7e1938fcbe01) |

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=aooiuu/any-reader&type=Date)](https://star-history.com/#aoouuu/any-reade&aooiuu/any-reader&Date)
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "any-reader",
"description": "摸鱼,自定义规则多站点聚合搜索阅读小说、漫画。包含JS规则解析库和VSCode插件。支持本地小说 TXT、EPUB",
"icon": "resources/icon.png",
"version": "1.3.5",
"version": "1.3.6",
"publisher": "aooiu",
"qna": "https://github.com/aooiuu/any-reader/issues",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "any-reader-web",
"version": "1.0.0-dev.8",
"version": "1.0.0-dev.10",
"private": true,
"scripts": {
"dev": "cross-env VITE_APP_PLATFORM=browser vite",
Expand Down

0 comments on commit 1f54e59

Please sign in to comment.