Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

textarea-markdown

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textarea-markdown - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

93

lib/textarea-markdown.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -9,11 +9,11 @@ Object.defineProperty(exports, "__esModule", {

require('whatwg-fetch');
require("whatwg-fetch");
var _markdownIt = require('markdown-it');
var _markdownIt = require("markdown-it");
var _markdownIt2 = _interopRequireDefault(_markdownIt);
var _magicBytes = require('magic-bytes.js');
var _magicBytes = require("magic-bytes.js");
var _filesize = require('filesize');
var _filesize = require("filesize");

@@ -35,8 +35,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

useUploader: true,
endPoint: '/api/image.json',
paramName: 'file',
responseKey: 'url',
endPoint: "/api/image.json",
paramName: "file",
responseKey: "url",
csrfToken: null,
placeholder: 'uploading %filename ...',
imageableExtensions: ['jpeg', 'png', 'gif'],
placeholder: "uploading %filename ...",
imageableExtensions: ["jpeg", "png", "gif"],
videoExtensions: ["mov", "mp4", "webm"],
afterPreview: function afterPreview() {},

@@ -47,3 +48,3 @@ plugins: [],

breaks: true,
langPrefix: 'language-',
langPrefix: "language-",
linkify: true

@@ -72,7 +73,7 @@ })

_createClass(TextareaMarkdown, [{
key: 'setPreview',
key: "setPreview",
value: function setPreview() {
var _this2 = this;
var selector = this.textarea.getAttribute('data-preview');
var selector = this.textarea.getAttribute("data-preview");
if (selector) {

@@ -85,3 +86,3 @@ Array.from(document.querySelectorAll(selector), function (e) {

}, {
key: 'drop',
key: "drop",
value: function drop(event) {

@@ -92,3 +93,3 @@ event.preventDefault();

}, {
key: 'paste',
key: "paste",
value: function paste(event) {

@@ -102,8 +103,8 @@ var files = event.clipboardData.files;

}, {
key: 'keyup',
value: function keyup(event) {
key: "keyup",
value: function keyup() {
this.applyPreview();
}
}, {
key: 'triggerEvent',
key: "triggerEvent",
value: function triggerEvent(element, event) {

@@ -117,13 +118,13 @@ if (document.createEvent) {

// IE
var evt = document.createEventObject();
return element.fireEvent("on" + event, evt);
var ieEvt = document.createEventObject();
return element.fireEvent("on" + event, ieEvt);
}
}
}, {
key: 'applyPreview',
key: "applyPreview",
value: function applyPreview() {
var _this3 = this;
var markdownOptions = this.options['markdownOptions'];
var plugins = this.options['plugins'];
var markdownOptions = this.options["markdownOptions"];
var plugins = this.options["plugins"];
if (this.previews) {

@@ -139,9 +140,9 @@ this.previews.forEach(function (preview) {

this.options['afterPreview']();
this.options["afterPreview"]();
}
}, {
key: 'uploadToOriginal',
value: function uploadToOriginal(file) {}
key: "uploadToOriginal",
value: function uploadToOriginal() {}
}, {
key: 'uploadAll',
key: "uploadAll",
value: function uploadAll(files) {

@@ -155,3 +156,3 @@ var _this4 = this;

}, {
key: 'upload',
key: "upload",
value: function upload(file) {

@@ -162,26 +163,26 @@ var _this5 = this;

reader.readAsArrayBuffer(file);
reader.onload = function (event) {
reader.onload = function () {
var bytes = new Uint8Array(reader.result);
var fileType = (0, _magicBytes.filetypeextension)(bytes)[0];
var fileSize = (0, _filesize.filesize)(file.size, { base: 10, standard: "jedec" });
var text = '![' + _this5.options['placeholder'].replace(/\%filename/, file.name) + ']()';
var text = "![" + _this5.options["placeholder"].replace(/\%filename/, file.name) + "]()";
var beforeRange = _this5.textarea.selectionStart;
var afterRange = text.length;
// const afterRange = text.length;
var beforeText = _this5.textarea.value.substring(0, beforeRange);
var afterText = _this5.textarea.value.substring(beforeRange, _this5.textarea.value.length);
_this5.textarea.value = beforeText + '\n' + text + '\n' + afterText;
_this5.textarea.value = beforeText + "\n" + text + "\n" + afterText;
var params = new FormData();
params.append(_this5.options['paramName'], file);
params.append(_this5.options["paramName"], file);
var headers = { 'X-Requested-With': 'XMLHttpRequest' };
if (_this5.options['csrfToken']) {
headers['X-CSRF-Token'] = _this5.options['csrfToken'];
var headers = { "X-Requested-With": "XMLHttpRequest" };
if (_this5.options["csrfToken"]) {
headers["X-CSRF-Token"] = _this5.options["csrfToken"];
}
fetch(_this5.options['endPoint'], {
method: 'POST',
fetch(_this5.options["endPoint"], {
method: "POST",
headers: headers,
credentials: 'same-origin',
credentials: "same-origin",
body: params

@@ -191,13 +192,15 @@ }).then(function (response) {

}).then(function (json) {
var responseKey = _this5.options['responseKey'];
var responseKey = _this5.options["responseKey"];
var url = json[responseKey];
if (_this5.options['imageableExtensions'].includes(fileType)) {
_this5.textarea.value = _this5.textarea.value.replace(text, '![' + file.name + '](' + url + ')\n');
if (_this5.options["imageableExtensions"].includes(fileType)) {
_this5.textarea.value = _this5.textarea.value.replace(text, "![" + file.name + "](" + url + ")\n");
} else if (_this5.options["videoExtensions"].includes(fileType)) {
_this5.textarea.value = _this5.textarea.value.replace(text, "<video controls src=\"" + url + "\"></video>\n");
} else {
_this5.textarea.value = _this5.textarea.value.replace(text, '[' + file.name + ' (' + fileSize + ')](' + url + ')\n');
_this5.textarea.value = _this5.textarea.value.replace(text, "[" + file.name + " (" + fileSize + ")](" + url + ")\n");
}
_this5.applyPreview();
}).catch(function (error) {
_this5.textarea.value = _this5.textarea.value.replace(text, '');
console.warn('parsing failed', error);
_this5.textarea.value = _this5.textarea.value.replace(text, "");
console.warn("parsing failed", error);
});

@@ -204,0 +207,0 @@ };

{
"name": "textarea-markdown",
"version": "1.3.4",
"version": "1.3.5",
"description": "Make textarea a markdown editor.",

@@ -5,0 +5,0 @@ "main": "lib/textarea-markdown.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc