2023-10-20 16:55:38 -07:00
# Markdown Editor
<script setup>
import { ref } from "vue";
2023-10-26 14:34:15 -07:00
const description = ref(null);
2023-10-27 17:20:13 -07:00
const description1 = ref(null);
2023-10-26 14:34:15 -07:00
const description2 = ref(null);
const description3 = ref(null);
2023-12-28 16:47:05 -08:00
const description4 = ref("Hello, world! This is a **bold ** statement.");
const isDisabled = ref(false);
2023-10-26 14:34:15 -07:00
const onImageUpload = (file) => {
return URL.createObjectURL(file).replace("blob:", "");
};
2023-10-20 16:55:38 -07:00
</script>
The Markdown editor allows for easy formatting of Markdown text whether the user is familiar with Markdown or not. It includes standard shortcuts such as `CTRL+B` for bold, `CTRL+I` for italic, and more.
## Full editor
<DemoContainer>
<MarkdownEditor v-model="description" />
</DemoContainer>
```vue
<script setup>
import { ref } from "vue";
const description = ref(null)
</script>
<MarkdownEditor v-model="description" />
```
2023-10-27 17:20:13 -07:00
## With options
<DemoContainer>
2023-10-30 16:59:43 -07:00
<MarkdownEditor v-model="description1" placeholder="Enter a description" max-length="800" max-height="400" />
2023-10-27 17:20:13 -07:00
</DemoContainer>
```vue
<script setup>
import { ref } from "vue";
const description = ref(null)
</script>
2023-10-30 16:59:43 -07:00
<MarkdownEditor v-model="description" placeholder="Enter a description" max-length="800" max-height="400" />
2023-10-27 17:20:13 -07:00
```
2023-10-26 14:34:15 -07:00
## With image upload
<DemoContainer>
<MarkdownEditor v-model="description2" :on-image-upload="onImageUpload" />
</DemoContainer>
```vue
<script setup lang="ts">
import { ref } from "vue";
const description = ref(null)
// Return a URL to the image for the editor to consume
const onImageUpload = (file: File): string => {
// Upload the file to your server and return a URL
// This example url will not work bc of proxy
2023-10-27 17:20:13 -07:00
// If the upload fails, throw an error and it will show as
// a Validation Error to the user
2023-10-26 14:34:15 -07:00
return URL.createObjectURL(file).replace("blob:", "");
};
</script>
<MarkdownEditor v-model="description" :on-image-upload="onImageUpload" />
```
2023-10-20 16:55:38 -07:00
## Without heading buttons
<DemoContainer>
2023-10-26 14:34:15 -07:00
<MarkdownEditor v-model="description3" :heading-buttons="false" />
2023-10-20 16:55:38 -07:00
</DemoContainer>
```vue
<script setup>
import { ref } from "vue";
const description = ref(null)
</script>
<MarkdownEditor v-model="description" :heading-buttons="false" />
```
2023-12-28 16:47:05 -08:00
## With default value
<DemoContainer>
<MarkdownEditor v-model="description4" />
</DemoContainer>
```vue
<script setup>
import { ref } from "vue";
const description = ref("Hello, world! This is a **bold ** statement.");
</script>
<MardownEditor v-model="description" />
```
## Disabled
<DemoContainer>
<Toggle v-model="isDisabled" label="Disabled" />
<MarkdownEditor v-model="description" :disabled="isDisabled" />
</DemoContainer>
```vue
<script setup>
import { ref } from "vue";
const description = ref(null);
</script>
<MardownEditor v-model="description" disabled />
```