GithubHelp home page GithubHelp logo

diplodoc-platform / transform Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 33.0 3.14 MB

Simple transformer YFM (Yandex Flavored Markdown) to HTML.

License: MIT License

JavaScript 1.35% SCSS 4.83% TypeScript 93.82%

transform's People

Contributors

3y3 avatar amje avatar burashka avatar chervyakovru avatar d3m1d0v avatar dependabot[bot] avatar feverqwe avatar gorgeousvlad avatar kiri111enz avatar kyzyl-ool avatar lunatic174 avatar main-kun avatar makamekm avatar makishvili avatar martyanovandrey avatar melikhov-dev avatar moki avatar myusosnovskay avatar nanov94 avatar postamentovich avatar rusandorx avatar smsochneg avatar tsufiev avatar v8tenko avatar vovcyan avatar vsesh avatar yc-ui-bot avatar yfm-team avatar yndx-birman avatar yndx-madfriend avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

transform's Issues

Incorrect Cut behavior inside lists

Minimal example

* {% cut "Cut 1" %}

  Some text

{% endcut %}

This inserts closing div in wrong place.

Expected to throw or to autofix cut closing tag.

Conditions in the code do not work in the included file

How to fix

Get the conditionsInCode flag from the options https://github.com/yandex-cloud/yfm-transform/blob/2fa7df8173c0c538c97842bd878335d7ba2fdaf1/src/transform/utilsFS.ts#L48
Pass the conditionsInCode flag to liquid options https://github.com/yandex-cloud/yfm-transform/blob/2fa7df8173c0c538c97842bd878335d7ba2fdaf1/src/transform/utilsFS.ts#L63

How to reproduce

#index.md
{% include [Code example](include.md) %}

#include.md

```bash
mongosh --norc \
{% if foo %}
--test inside bash
{% else %}
--test-false
{% endif %}

Fix webpack dev mode warnings

Switched to @gravity-ui/app-builder as build library in my project and got this warnings in dev mode:

WARNING in ./node_modules/@doc-tools/transform/dist/css/yfm.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[3].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[3].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[1].oneOf[3].use[3]!./node_modules/@doc-tools/transform/dist/css/yfm.css)
Module Warning (from ./node_modules/resolve-url-loader/index.js):
resolve-url-loader: webpack misconfiguration
  webpack or the upstream loader did not supply a source-map

A way to add attributes to links

I couldn't find it in documentation, so, most likely, the answer to my question is No, but is it possible to add arbitrary attributes to the resulted HTML for links? For example, I want links to have target attribute set to "_blank" to have links open in a separate tab. It seems some other markdown processors allow this. Does yfm-transform support it?

Proposal: Refactor Cut plugin to use <detail> Tag

We currently use <div> tags for collapsible content sections.

<div class="yfm-cut open">
    <div class="yfm-cut-title">Cut header</div>
    <div class="yfm-cut-content">
        <p>Content displayed when clicked.</p>
    </div>
</div>

I propose refactoring these to use HTML's <details> tag to enhance accessibility, usability, and maintainability.

<details>
  <summary>Cut header</summary>
  Content displayed when clicked.
</details>

Justification:

  1. Accessibility: <details> provides built-in keyboard and screen reader support, aligning with WCAG standards.
  2. Native Functionality: Reduces JavaScript reliance, enhancing load times and reducing UI bugs with browser-handled collapsible features.
  3. Usability & User Experience: Offers a standardized interaction model for users.
  4. Maintenance: Simplifies code and guards against deprecation with standard HTML5.

Change plugin configuration method

At current time all plugins consumes union (global) configuration object, which passes from md constructor.

This configuration method can be buggy on large scope of plugins.

Proposal:

Move plugin configuration to closure:

export function somePlugn(options) {
    return function pluginBody(md) {
        if (options.flag) {
            ...
        }
    }
}

feat(rules/link_implicit): implicit links parsing

http://diplodoc.com would not be parsed as link without wrapping it in links syntax

e.g: [http://diplodoc.com](http://diplodoc.com) or <http://diplodoc.com>

playground link

most platforms have text that makes a link transformed into links automatically, creating expectations from users to have that feature out of the box.

look into implementing plugin that will parse text that looks like a link as link

be cautious of performance degradation.

runtime error when transform yfm-cut with curly brackets in title

Markup:

{% cut "{title}" %}

content

{% endcut %}

transform() crash with error

Uncaught TypeError: Cannot read properties of undefined (reading 'type')
    at exports.getMatchingOpeningToken (utils.js:236:1)
    at Object.transform (patterns.js:328:1)
    at Array.curlyAttrs (index.js:30:1)
    at Core.process (parser_core.js:54:1)
    at MarkdownIt.parseInline (index.js:561:1)
    at Array.plugin (cut.js:32:1)
    at Core.process (parser_core.js:54:1)
    at MarkdownIt.parse (index.js:524:1)
    at md.js:69:1
    at transform (index.js:28:1)

Example in playground

Broken order of ordered lists in FireFox

I found an issue with ordered lists (ol) in FireFox while using YFM. You can see it in this demo: https://codepen.io/isqua/pen/qBxgGjN?editors=1100

Following code will help to reproduce the bug
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>YFM Ordered List</title>
    <!-- The stylesheet is taken from https://ydocs.tech -->
    <link rel="stylesheet" href="https://yastatic.net/s3/cloud/docs-viewer-external/static/freeze/en/vendor.4bed8c5e.css">
</head>
<body>
    <h1>YFM: broken order of ordered lists</h1>
    <ol>
        <li>
            <p>YFM list one:</p>
            <div class="yfm">
                <ol>
                    <li>First list, first element</li>
                    <li>First list, second element</li>
                </ol>
            </div>
        </li>
        <li>
            <p>YFM list two:</p>
            <div class="yfm">
                <ol>
                    <li>Second list, first element</li>
                    <li>Second list, second element</li>
                </ol>
            </div>
        </li>
        <li>
            <p>YFM list three:</p>
            <div class="yfm">
                <ol>
                    <li>Third list, first element</li>
                    <li>Third list, second element</li>
                </ol>
            </div>
        </li>
    </ol>
</body>
</html>

In FireFox 101.0.1 the code produces following output:

Screen Shot 2022-06-15 at 19 51 16

As you see, text «YFM list two» is numbered as 4, but expected number is 2. And text «YFM list three» is numbered as 7, but expected number is 3.

Here is some explanation of this behaviour on FireFox Bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=1545746#c5

Looks like they are right :) I suppose we need to change counter-reset of ol from list to list-item list.

Add support for `renderInline`

In some cases we need to render markdown that suitable for displaying as one-liner -- without images, paragraphs, list and etc.

markdown-it has method to achieve this renderInline, it would be nice to have it in transform.

fix(plugins/anchors): heading duplicate text content

selecting heading and copying it leads to duplicate text:

select and ctrl+c on this text:

# heading {#anchor}

upon doing ctrl+v leads to:

heading heading

playground example: https://diplodoc-platform.github.io/playground/?input=%23%2520heading%2520

this is happening because every anchor(even implicit one) generates token of type anchor_hidden_desc with heading text as content and rendered as a hidden span(all of that is done for SEO purposes).

parser/transformation:

// SEO: render invisible heading title because link must have text content.
const hiddenDesc = new state.Token('anchor_hidden_desc', '', 0);
hiddenDesc.content = title;
return [open, hiddenDesc, close];

renderer:

md.renderer.rules.anchor_hidden_desc = function (tokens, index) {
return '<span class="visually-hidden">' + escapeHtml(tokens[index].content) + '</span>';
};

css rules:

.visually-hidden {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
white-space: nowrap;
border: 0;
clip-path: inset(100%);
}

prevent select of hidden text with user-select: none

original issue for seo implementation: #244

should not affect SEO: https://webmasters.stackexchange.com/questions/99855/is-text-that-use-css-user-select-none-indexed-and-ranked-by-search-engines

Add transform profile

Add transform profile info about each plugin.

It should be enabled by profile option. (Default: false).

If profile option is enabled, transform should expose profile info in result object:

{
    "html": "...",
    "profile": {
        <some popular profile format?>
        <compatible with web inspector?>
    }
}

Profiler can affect performance.

Profiler should be platform agnostic.

Profiler should be implemented in transformer itself, not in each plugin.

Change default interface to async

At current time transform is sync function.

This limits power of transformation.

Propose to add transform.async in minor with new experimental features.
Propose to change transform interface to async in major.

Text of headers is duplicated

How to reproduce:

$ mkdir doc3 && cd doc3 && npm install @doc-tools/transform@latest
$ node -e "console.log(require('@doc-tools/transform')('## test header', {allowHTML: true}))" 
{
  result: {
    meta: {},
    assets: undefined,
    headings: [ [Object] ],
    title: '',
    html: '<h2 id="test-header"><a href="#test-header" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">test header</span></a>test header</h2>\n'
  },
  logs: { info: [], warn: [], error: [], disabled: [] }
}

test header string is present twice:

test headertest header

Support nested tabs

The markup

{% list tabs %}

- tab1

  content of tab1
  
  {% list tabs %}

  - nested_tab1

    content of nested tab1

  {% endlist %}

{% endlist %}

converts to this HTML:

image

settings.md file is missing from repository

In the following line of the en and ru README.md file * Input data: [Settings](settings.md) and a string with YFM. the settings.md file is specified, but it is nowhere to be found.

Proposition for improvements to note plugin

There are several propositions:

  1. Add more note types with more color options (e.g. grey)
  2. What about removal on title attribute for note. It is optional, but when it is absent it still renders as empty block.
    What about going from this syntax:
    {% note title="title" %}
    
    content
    
    {% endnote%}
    
    To this:
    {% note %}
    
    *title*
    
    content
    
    {% endnote%}
    

fix(plugins/links): mark link_open as reflink

plugins/links

We have reflink syntax, this markup [{#T}](file.md) extracts title from file.md and uses it as link text.

We need to mark link_open token with markup: reflink(analogous to how autolinks are parsed).

Right now i am doing it inside @diplodoc-platform/markdown-translation library when rendering tokens into XML.

Objectively links of reflink type should just be marked as such by parser.

to easier understand the token structure checkout tokens tab: link to the playground

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.