diff --git a/README.md b/README.md index 6de9440d..cab740aa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@

✨ Markdown Preview for (Neo)vim ✨

+### THIS IS A FORKED PROJECT + +Please give all your love to the [original project](https://github.com/iamcco/markdown-preview.nvim), the only difference between the two is that I changed the default page width in `app/_static/page.css`. If this could be a configurable setting, I'd be happy to retire this fork. + > Powered by ❤️ ### Introduction diff --git a/app/_static/page.css b/app/_static/page.css index 499f840c..940d95ec 100644 --- a/app/_static/page.css +++ b/app/_static/page.css @@ -1,4 +1,7 @@ -html,body,#__next,main { +html, +body, +#__next, +main { min-height: 100vh; margin: 0; } @@ -40,7 +43,7 @@ main { #page-ctn { margin: 0 auto; - max-width: 900px; + max-width: 500px; color: var(--foreground-color); } diff --git a/app/pages/index.jsx b/app/pages/index.jsx index ebc89baf..d54ecf70 100644 --- a/app/pages/index.jsx +++ b/app/pages/index.jsx @@ -23,7 +23,7 @@ import codeUml from './plantuml' import scrollToLine from './scroll' import { meta } from './meta'; import markdownImSize from './markdown-it-imsize' -import { escape} from './utils'; +import { escape } from './utils'; const anchorSymbol = '' @@ -52,13 +52,12 @@ const DEFAULT_OPTIONS = { // Highlighter function. Should return escaped HTML, // or '' if the source string is not changed and should be escaped externally. // If result starts with ${ - hljs.highlight(lang, str, true).value - }`; - } catch (__) {} + return `
${hljs.highlight(lang, str, true).value
+            }
`; + } catch (__) { } } return `
${escape(str)}
`; @@ -90,7 +89,8 @@ export default class PreviewPage extends React.Component { theme: '', themeModeIsVisible: false, contentEditable: false, - disableFilename: 1 + disableFilename: 1, + pageCtnMaxWidth: '' } this.showThemeButton = this.showThemeButton.bind(this) this.hideThemeButton = this.hideThemeButton.bind(this) @@ -128,6 +128,10 @@ export default class PreviewPage extends React.Component { } }) + socket.onAny((event, ...args) => { + console.log(`🛰 Received socket event: ${event}`, args); + }); + window.socket = socket socket.on('connect', this.onConnect.bind(this)) @@ -177,8 +181,10 @@ export default class PreviewPage extends React.Component { pageTitle = '', theme, name = '', - content + content, + pageCtnMaxWidth = '' }) { + console.log('🚀 onRefreshContent: pageCtnMaxWidth =', pageCtnMaxWidth); if (!this.md) { const { mkit = {}, @@ -275,13 +281,14 @@ export default class PreviewPage extends React.Component { })(name), ...( refreshContent - ? { content: this.md.render(newContent) } - : {} + ? { content: this.md.render(newContent) } + : {} ), pageTitle, theme, contentEditable: options.content_editable, - disableFilename: options.disable_filename + disableFilename: options.disable_filename, + pageCtnMaxWidth, }, () => { if (refreshContent) { try { @@ -325,8 +332,11 @@ export default class PreviewPage extends React.Component { themeModeIsVisible, contentEditable, disableFilename, + pageCtnMaxWidth, } = this.state + console.log('Rendered pageCtnMaxWidth:', pageCtnMaxWidth); + return ( @@ -351,8 +361,12 @@ export default class PreviewPage extends React.Component {
-
- { disableFilename == 0 && +
+ {disableFilename == 0 && }
{ + console.log('💥 Client connected!', client.id); const { handshake = { query: {} } } = client const bufnr = handshake.query.bufnr @@ -65,6 +66,7 @@ exports.run = function () { const buffers = await plugin.nvim.buffers buffers.forEach(async (buffer) => { if (buffer.id === Number(bufnr)) { + console.log('✅ Found matching buffer:', buffer.id); const winline = await plugin.nvim.call('winline') const currentWindow = await plugin.nvim.window const winheight = await plugin.nvim.call('winheight', currentWindow.id) @@ -74,7 +76,10 @@ exports.run = function () { const theme = await plugin.nvim.getVar('mkdp_theme') const name = await buffer.name const content = await buffer.getLines() + const pageCtnMaxWidth = await plugin.nvim.getVar('mkdp_page_ctn_max_width') + console.log('📡 Sending pageCtnMaxWidth =', pageCtnMaxWidth); // <- add this! const currentBuffer = await plugin.nvim.buffer + console.log('🚀 Emitting refresh_content'); client.emit('refresh_content', { options, isActive: currentBuffer.id === buffer.id, @@ -84,12 +89,13 @@ exports.run = function () { pageTitle, theme, name, - content + content, + pageCtnMaxWidth }) } }) - client.on('disconnect', function () { + client.on('disconnect', function() { logger.info('disconnect: ', client.id) clients[bufnr] = (clients[bufnr] || []).map(c => c.id !== client.id) // update vim variable @@ -97,7 +103,7 @@ exports.run = function () { }) }) - async function startServer () { + async function startServer() { const openToTheWord = await plugin.nvim.getVar('mkdp_open_to_the_world') const host = openToTheWord ? '0.0.0.0' : '127.0.0.1' let port = await plugin.nvim.getVar('mkdp_port') @@ -105,17 +111,17 @@ exports.run = function () { server.listen({ host, port - }, function () { + }, function() { logger.info('server run: ', port) - function refreshPage ({ bufnr, data }) { + function refreshPage({ bufnr, data }) { logger.info('refresh page: ', bufnr) - ;(clients[bufnr] || []).forEach(c => { - if (c.connected) { - c.emit('refresh_content', data) - } - }) + ; (clients[bufnr] || []).forEach(c => { + if (c.connected) { + c.emit('refresh_content', data) + } + }) } - function closePage ({ bufnr }) { + function closePage({ bufnr }) { logger.info('close page: ', bufnr) clients[bufnr] = (clients[bufnr] || []).filter(c => { if (c.connected) { @@ -125,10 +131,10 @@ exports.run = function () { return true }) } - function closeAllPages () { + function closeAllPages() { logger.info('close all pages') Object.keys(clients).forEach(bufnr => { - ;(clients[bufnr] || []).forEach(c => { + ; (clients[bufnr] || []).forEach(c => { if (c.connected) { c.emit('close_page') } @@ -136,7 +142,7 @@ exports.run = function () { }) clients = {} } - async function openBrowser ({ bufnr }) { + async function openBrowser({ bufnr }) { const combinePreview = await plugin.nvim.getVar('mkdp_combine_preview') if (combinePreview && Object.values(clients).some(cs => cs.some(c => c.connected))) { logger.info(`combine preview page: `, bufnr) diff --git a/plugin/mkdp.vim b/plugin/mkdp.vim index 9b283074..f3ef9faa 100644 --- a/plugin/mkdp.vim +++ b/plugin/mkdp.vim @@ -116,6 +116,10 @@ if !exists('g:mkdp_combine_preview_auto_refresh') let g:mkdp_combine_preview_auto_refresh = 1 endif +if !exists('g:mkdp_page_ctn_max_width') + let g:mkdp_page_ctn_max_width = '' +endif + " if there are any active preview client let g:mkdp_clients_active = 0 diff --git a/src/attach/index.ts b/src/attach/index.ts index f11d48b0..d58e7d93 100644 --- a/src/attach/index.ts +++ b/src/attach/index.ts @@ -35,7 +35,9 @@ export default function(options: Attach): IPlugin { nvim.on('notification', async (method: string, args: any[]) => { const opts = args[0] || args const bufnr = opts.bufnr + console.log('💡 bufnr from client =', bufnr); const buffers = await nvim.buffers + console.log('📚 Buffers from nvim =', buffers.map(b => b.id)); const buffer = buffers.find(b => b.id === bufnr) if (method === 'refresh_content') { const winline = await nvim.call('winline')