Skip to content

Commit

Permalink
feat: support wxml
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Aug 13, 2024
1 parent ed8b30c commit ad7a855
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions composables/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { javascript } from './javascript'
import { json } from './json'
import { svelte } from './svelte'
import { vue } from './vue'
import { wxml } from './wxml'
import type { AsyncComponentLoader } from 'vue'

export type MonacoLanguage =
Expand Down Expand Up @@ -64,5 +65,6 @@ export const LANGUAGES = {
css,
html,
json,
wxml,
}
export type Language = keyof typeof LANGUAGES
1 change: 1 addition & 0 deletions composables/parser/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as svelteTemplate } from './svelte.svelte?raw'
export { default as cssTemplate } from './css.css?raw'
export { default as jsonTemplate } from './json.json?raw'
export { default as htmlTemplate } from './html.html?raw'
export { default as wxmlTemplate } from './wxml.wxml?raw'
36 changes: 36 additions & 0 deletions composables/parser/template/wxml.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!-- wxs -->
<wxs module="m1">
var msg = 'hello world'

module.exports.message = msg
</wxs>
<view> {{ m1.message }} </view>

<!-- import -->
<import src="item.wxml" />
<template is="item" data="{{text: 'forbar'}}" />

<!-- include -->
<include src="header.wxml" />
<view> body </view>
<include src="footer.wxml" />

<view class="search-contianer">
<view
class="search"
style="height:{{ navHeight }}px;padding-top:{{ navTop }}px"
>
<view class="search-title" src="../../images/actLogo/ytlogo.png">
{{ mallName }}
</view>
<input
placeholder-class="search-placeholder"
type="text"
placeholder="please enter keyword for search"
disabled
value="{{ name }}"
bindinput="bindinput"
bindtap="goSearch"
/>
</view>
</view>
33 changes: 33 additions & 0 deletions composables/parser/wxml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { wxmlTemplate } from './template'
import type { Parser } from '.'

export const wxmlParser: Parser<any, any> = {
id: 'wxml-parser',
label: '@wxml/parser',
icon: 'i-vscode-icons:file-type-wxml',
link: 'https://github.com/wxmlfile/wxml-parser',
options: {
configurable: false,
defaultValue: {},
editorLanguage: 'json',
},
pkgName: '@wxml/parser',
init: (pkg) =>
importUrl(`https://cdn.jsdelivr.net/npm/${pkg}/+esm`).then(
(mod) => mod.default,
),
version: fetchVersion,
parse(code) {
return this.parse(code)
},
editorLanguage: 'html',
getAstLocation,
}

export const wxml: LanguageOption = {
label: 'WXML',
// @unocss-include
icon: 'i-vscode-icons:file-type-wxml',
parsers: [wxmlParser],
codeTemplate: wxmlTemplate,
}

0 comments on commit ad7a855

Please sign in to comment.