(1)Linkify--自动匹配电子邮件,网址,电话

public class MainActivity extends Activity {
private String TAG=MainActivity.class.getSimpleName();
EditText editText; 
    TextView textView; 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=(EditText)this.findViewById(R.id.inputText); 
        textView=(TextView)this.findViewById(R.id.viewText); 


        editText.setOnKeyListener(new OnKeyListener() { 
            @Override 
            public boolean onKey(View v, int keyCode, KeyEvent event) { 
                textView.setText(editText.getText()); 
                Linkify.addLinks(textView, Linkify.EMAIL_ADDRESSES|Linkify.PHONE_NUMBERS|Linkify.WEB_URLS); 
                return false; 
            } 
        }); 
}

}

--------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <TextView
         android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:text="http://www.517dv.com" />
    <EditText 
        android:layout_marginTop="5dp"
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:id="@+id/inputText"> 
    </EditText> 
    <TextView 
         android:layout_marginTop="5dp"
        android:layout_height="wrap_content" 
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_width="fill_parent" 
        android:id="@+id/viewText" 
        android:text=""></TextView> 
</LinearLayout>
在 Vue 中使用 Markdown 生成文档时,可以通过以下步骤自动生成侧边栏目录: 1. 在项目中安装 `markdown-it` 和 `markdown-it-anchor` 库: ```bash npm install markdown-it markdown-it-anchor --save ``` 2. 在 Vue 组件中引入并初始化 `markdown-it` 和 `markdown-it-anchor`: ```javascript import MarkdownIt from 'markdown-it' import MarkdownItAnchor from 'markdown-it-anchor' const md = new MarkdownIt({ html: true, linkify: true, typographer: true, }) md.use(MarkdownItAnchor) ``` 3. 在 Vue 组件中使用 `v-html` 指令渲染 Markdown 文本,并使用 `@hook:mounted` 钩子函数监听渲染完成事件,在事件处理函数中获取文档中所有标题标签(如 `h1`、`h2` 等),并根据标题级别生成目录树: ```html <template> <div> <div v-html="html"></div> <div class="sidebar"> <ul> <li v-for="item in toc" :key="item.id"> <a :href="'#' + item.id">{{ item.text }}</a> <ul v-if="item.children"> <li v-for="child in item.children" :key="child.id"> <a :href="'#' + child.id">{{ child.text }}</a> </li> </ul> </li> </ul> </div> </div> </template> <script> export default { data() { return { html: '', toc: [], } }, mounted() { this.html = md.render('# Hello World\n## Introduction\n### Features\n### Installation\n## Usage\n## API Reference') this.$nextTick(() => { const headers = Array.from(document.querySelectorAll('h1, h2, h3, h4, h5, h6')) this.toc = headers.map(header => ({ id: header.id, text: header.textContent, level: Number(header.tagName[1]), })).reduce((acc, header) => { let lastItem = acc[acc.length - 1] if (!lastItem || header.level <= lastItem.level) { acc.push(header) } else { let parent = lastItem while (parent.children && header.level > parent.level) { parent = parent.children[parent.children.length - 1] } if (!parent.children) { parent.children = [] } parent.children.push(header) } return acc }, []) }) }, } </script> ``` 4. 在 Vue 组件的样式中定义侧边栏样式: ```css .sidebar { position: fixed; top: 0; right: 0; bottom: 0; width: 200px; padding: 20px; overflow-y: auto; } ``` 这样就可以在 Vue Markdown 文档中自动生成侧边栏目录了。当然,这只是一个简单的示例,实际项目中可能需要根据具体需求进行一些定制化调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值