npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@corgicoding/markdown-editor

v0.0.1

Published

Vue components based on monaco

Downloads

2

Readme

corgicoding-markdown-vue

Vue components based on monaco and markdown-it. Compatible with vue3.x

global use

First, you need to install this package on your project.

npm install @corgicoding/markdown-vue -S

# OR
pnpm install @corgicoding/markdown-vue -S

After that, you can import it globally in main.js / main.ts.

import markdownVue from '@corgicoding/markdown-vue';
createApp(App).use(markdownVue).mount('#app');

on demand Import

Of course, you can import on demand in the following ways

  • MarkdownEditor
import { MarkdownEditor } from '@corgicoding/markdown-vue';
  • MarkdownRender
import { MarkdownRender } from '@corgicoding/markdown-vue';

how to use

this is a example

<script setup lang="ts">
import { ref } from 'vue';

const textValue = ref(`> *corgicoding: Edit here...*
`);
</script>

<template>
  <div style="width: 100%; height: 100%; position: relative; display: flex">
    <div style="width: 50%; height: 100%; position: relative">
      <MarkdownEditor
        v-model="textValue"
        :options="{
          fontSize: 16,
          theme: 'vs'
        }"
      ></MarkdownEditor>
    </div>

    <MarkdownRender v-model="textValue"></MarkdownRender>
  </div>
</template>

<style></style>

dev

more detail: https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin monaco docs: https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md#integrating-the-esm-version-of-the-monaco-editor

sometimes, you should install monaco-editor-webpack-plugin ,

  "devDependencies": {
    "monaco-editor-webpack-plugin": "^4.1.1"
  },

and add the following code in vue.config.js

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
  // ......
  configureWebpack: {
    plugins: [
      new MonacoWebpackPlugin({
        // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
        languages: [
          'javascript',
          'css',
          'html',
          'typescript',
          'json',
          'markdown'
        ]
      })
    ]
  }
};

Components

export interface EditorOptions {
  readonly?: boolean;
  language?: string;
  theme?: string;
  minimap?: boolean;
  scrollbarSize?: number;
  wordWrap?: 'off' | 'on' | 'wordWrapColumn' | 'bounded' | undefined;
  automaticLayout?: boolean;
  autoIndent?: 'none' | 'keep' | 'brackets' | 'advanced' | 'full' | undefined;
  selectOnLineNumbers?: boolean;
  roundedSelection?: boolean;
  readOnly?: boolean; // 只读
  cursorStyle?:
    | 'line'
    | 'block'
    | 'underline'
    | 'line-thin'
    | 'block-outline'
    | 'underline-thin'
    | undefined; // 光标样式
  glyphMargin?: boolean; // 字形边缘
  useTabStops?: boolean;
  fontSize?: number; // 字体大小
  [key: string]: any;
}

export interface EditorAction {
  id: string;
  label: string;
  groupId: string;
  handler: () => void;
}

export type { Options as MarkdownItOptions } from 'markdown-it';

MarkdownEditor

const props = defineProps<{
  modelValue?: string;
  options?: EditorOptions;
  forceOptions?: monaco.editor.IStandaloneEditorConstructionOptions;
  actions?: EditorAction[];
}>();

const defaultOptions: EditorOptions = {
  readonly: false,
  language: 'markdown',
  theme: 'vs',
  minimap: false,
  scrollbarSize: 10,
  wordWrap: 'on',
  automaticLayout: true,
  autoIndent: 'none',
  selectOnLineNumbers: true,
  roundedSelection: false,
  readOnly: false, // 只读
  cursorStyle: 'line', // 光标样式
  glyphMargin: true, // 字形边缘
  useTabStops: false,
  fontSize: 16 // 字体大小
};

const Emits = defineEmits(['update:modelValue', 'editorScroll']);

const execMethods = (
  fn: (editor: monaco.editor.IStandaloneCodeEditor) => void
) => {
  if (monacoEditor.value) {
    fn(monacoEditor.value);
  }
};

defineExpose({
  monacoEditor,
  textValue,
  execMethods
});

RenderPage

const props = withDefaults(
  defineProps<{
    modelValue: string;
    plugins?: Array<any>;
    options?: Options;
  }>(),
  {
    plugins: () => [],
    options: () => ({
      html: true,
      linkify: true,
      break: true,
      highlight: function (str: string, lang: any) {
        if (lang && highlight.getLanguage(lang)) {
          try {
            return (
              '<pre class="hljs"><code>' +
              highlight.highlight(lang, str, true).value +
              '</code></pre>'
            );
            // eslint-disable-next-line no-empty
          } catch (__) {}
        }

        return (
          '<pre class="hljs"><code>' +
          highlight.highlight('js', str, true).value +
          '</code></pre>'
        ); // Use additional default escaping
      }
    })
  }
);

const Emits = defineEmits(['update:modelValue']);

const execMethods = (fn: (renderInstance: MarkdownIt) => void) => {
  if (renderInstance.value) {
    fn(renderInstance.value);
  }
};

defineExpose({
  renderInstance,
  execMethods
});