Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Fix ability to use HTML fragments #4812

Merged
merged 1 commit into from
Jun 1, 2022
Merged

Add/Fix ability to use HTML fragments #4812

merged 1 commit into from
Jun 1, 2022

Conversation

BenSouchet
Copy link
Contributor

Issue #4811 Add/Fix ability to use HTML fragments

Description of changes:

I fixed the existing code handling the HTML fragment feature, I haven't remove the obsolete DocumentFragment class but this class either was never really finished or pieces were lost over time.

I decided to use the exact same route as for non-fragment document, and do the required work to reconnect with the existing features.

I test it by compiling with node ./Makefile.dryice.js on a clean new web server and it's works.

Risks

Since the feature didn't work for at least the last 4/5 years I don't think new bugs will be introduced with these changes.
Few have tried to use fragment (see issue #3518), but was face to the incomplete DocumentFragment class.

How to use Fragment

You need to pass to the HTML mode an object with a property called fragmentContext and the value need to be the name of a valid DOM Element tag name (head, body, div, footer, ...) ensure it in lowercase without extra space(s).

After a discussion with @andrewnester , my setup is:

let containerId = 'my-awesome-ace';

let editor = ace.edit(containerId);

let HtmlMode = require("ace/mode/html").Mode;
editor.session.setMode(new HtmlMode({fragmentContext: "body"});

If for a reason I ignore you have an error telling you require("ace/mode/html") return undefined

Do something like:

let config = require("ace/config");
let net = require("ace/lib/net");

function _initialize() {
    let containerId = 'my-awesome-ace';

    let editor = ace.edit(containerId);

    let HtmlMode = require("ace/mode/html").Mode;
    editor.session.setMode(new HtmlMode({fragmentContext: "body"});
}

net.loadScript(config.moduleUrl("ace/mode/html", "mode"), _initialize);

If you use the no-conflic version of ace, please prefix the require with ace..

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #4812 (cb513e0) into master (57ded09) will increase coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #4812      +/-   ##
==========================================
+ Coverage   71.12%   71.16%   +0.04%     
==========================================
  Files         554      554              
  Lines       55711    55716       +5     
  Branches    10419    10420       +1     
==========================================
+ Hits        39623    39652      +29     
+ Misses      16088    16064      -24     
Flag Coverage Δ
unittests 71.16% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/ace/mouse/default_gutter_handler.js 25.96% <0.00%> (-0.78%) ⬇️
lib/ace/tooltip.js 43.75% <0.00%> (+0.27%) ⬆️
lib/ace/editor.js 81.70% <0.00%> (+1.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57ded09...cb513e0. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants