Fix greentext processor
This commit is contained in:
parent
caf7b28b22
commit
dee1cfa691
3 changed files with 16 additions and 4 deletions
|
@ -231,6 +231,7 @@ import { useCurrentUser } from "@/store/user"
|
||||||
import { CRYPTOCURRENCIES } from "@/utils/cryptocurrencies"
|
import { CRYPTOCURRENCIES } from "@/utils/cryptocurrencies"
|
||||||
import { getWallet } from "@/utils/ethereum"
|
import { getWallet } from "@/utils/ethereum"
|
||||||
import { formatDate } from "@/utils/format"
|
import { formatDate } from "@/utils/format"
|
||||||
|
import { addGreentext } from "@/utils/greentext"
|
||||||
|
|
||||||
interface PaymentOption {
|
interface PaymentOption {
|
||||||
code: string;
|
code: string;
|
||||||
|
@ -311,10 +312,7 @@ export default class PostComponent extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
get content(): string {
|
get content(): string {
|
||||||
// Add greentext
|
const content = addGreentext(this.post.content)
|
||||||
const greentextRegexp = /(?<=^|>)(>.+)(?=$|<)/gm
|
|
||||||
const content = this.post.content
|
|
||||||
.replaceAll(greentextRegexp, '<span class="greentext">$1</span>')
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
src/utils/greentext.ts
Normal file
4
src/utils/greentext.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export function addGreentext(text: string): string {
|
||||||
|
const greentextRegexp = /(?<=^|>)(>[^<]+)(?=$|<)/gm
|
||||||
|
return text.replace(greentextRegexp, '<span class="greentext">$1</span>')
|
||||||
|
}
|
10
tests/unit/greentext.spec.ts
Normal file
10
tests/unit/greentext.spec.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { expect } from "chai"
|
||||||
|
import { addGreentext } from "@/utils/greentext"
|
||||||
|
|
||||||
|
describe("Greentext", () => {
|
||||||
|
it("Should add greentext class", () => {
|
||||||
|
const text = "test<br>>greentext1<br>abc<br>>greentext2<br>xyz"
|
||||||
|
const result = addGreentext(text)
|
||||||
|
expect(result).to.equal('test<br><span class="greentext">>greentext1</span><br>abc<br><span class="greentext">>greentext2</span><br>xyz')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue