Giter Club home page Giter Club logo

oik-css's Introduction

oik-css

banner

Description

Allows internal CSS styling to be included in the content of the page.

  • Use the CSS block to add custom CSS.
    • Use the GeSHi block to syntax highlight: CSS, HTML, JavaScript, jQuery, PHP, MySQL or None.

For backward compatibility:

  • Use the [bw_css] shortcode to add custom CSS as and when you need it.

For designers, developers and documenters [bw_css] supports echoing of the custom CSS, allowing you to document the CSS you are using. For readability, the CSS is processed using the Generic Syntax Highlighter (GeSHi) processing.

    • Use the [bw_geshi] shortcode for syntax highlighting of: CSS, HTML(5), JavaScript and jQuery, PHP and MySQL.
  • Also supports language: none.

If the oik base plugin is activated

  • Use the [bw_autop] shortcode to disable or re-enable WordPress's wpautop() logic.

  • Use the experimental [bw_background] shortcode to display an attached image in the background.

Installation

  1. Upload the contents of the oik-css plugin to the `/wp-content/plugins/oik-css' directory
  2. Activate the oik-css plugin through the 'Plugins' menu in WordPress
  3. Use the CSS and GeSHi blocks within your content.

Frequently Asked Questions

What are the dependencies?

This code is no longer dependent upon the oik base plugin; it uses shared libraries. If you want to use the shortcodes then using oik v3.3.7 or higher is still recommended.

What is the syntax?

[bw_css] your CSS goes here [/bw_css]
  • Note: The ending shortcode tag [/bw_css] is required

How do I get the GeSHi output?

Either

[bw_css .] your CSS goes here[/bw_css]

or

[bw_css text="Annotation to the CSS that will follow"] your CSS goes here[/bw_css]

How do I get GeSHi output for other languages?

Use the [bw_geshi] shortcode. e.g. [bw_geshi html]<h3>[bw_css], [bw_geshi] & [bw_background]</h3><p>Cool, lazy smart shortcodes from oik-plugins.</p> [/bw_geshi]

Supported languages are:

  • CSS
  • HTML(5)
  • JavaScript and jQuery
  • PHP
  • MySQL
  • none

If you want to display syntax highlighted CSS without affecting the current display use [bw_geshi css].

What version of GeSHi does oik-css use?

oik-css delivers a subset of GeSHi version 1.0.9.0, which was released in May 2017, with modifications to support PHP 7.2

Only a small selection of the languages are supported by oik-css. These are the languages primarily used by WordPress.

  • Note: oik-css will only load the GeSHi code if it is not already loaded.

What about Gutenberg?

oik-css has been tested with the Gutenberg plugin and some problems were detected. For details see #9. Changes have been made to undo the unwanted wpautop processing that affected the output of the bw_geshi shortcode.

In the future you may want to convert your shortcodes to blocks. We are developing a new plugin for this... https://github.com/bobbingwide/oik-block. This new plugin depends on Gutenberg, the oik base plugin and oik-css.

Screenshots

  1. CSS block example
  2. GeSHi block example
  3. [bw_css] - syntax and examples
  4. [bw_geshi] - examples
  5. oik-CSS options - available when oik is active

Upgrade Notice

2.1.3

Each block has its own entry point. Now supports PHP 8.3.

Changelog

2.1.3

  • Changed: Support PHP 8.3 #27
  • Changed: Update wp-scripts and rebuild using separate entry points #26
  • Tested: With WordPress 6.5-RC2 and WordPress Multisite
  • Tested: With PHP 8.3
  • Tested: With PHPUnit 9.6

Further reading

If you want to read more about the oik plugins then please visit the oik plugin "OIK - OIK Information Kit"

oik-css's People

Contributors

bobbingwide avatar

Watchers

 avatar  avatar

oik-css's Issues

Support for WordPress 5.0 and the new editor - Gutenberg

Since early 2017 a new editor has been under development. Code named Gutenberg this new editor is being developed as a feature plugin. It is expected to be merged into core for WordPress 5.0.

We need to be aware of Gutenberg and to attempt to be compatible with it.
Actually, it's the other way round. Gutenberg needs to be backward compatible with us.

According to Gutenberg's README.

Posts are backwards compatible, and shortcodes will still work.

That's not the case right now.

The following shortcodes, which depend on the new line character being respected in content, may not work correctly after being manipulated by the Gutenberg editor
[bw_css]
[bw_geshi]

Area Problem Reference / Solution
bw_geshi Unexpected <br /> tags in output gutenberg_autop needs to be removed from priority 8
bw_css Seems OK

Analysis

The reason we see br's for the [bw_geshi] output is because gutenberg_wpautop() introduces them but bw_geshi() doesn't strip them.
We don't see them in [bw_css] because the oik_css() function removes them using bw_remove_unwanted_tags().

Improve CSS and GeSHi blocks to support loading `src` from a file

Using the shared library logic developed in bobbingwide/oik-bob-bing-wide#40 for the CSV block, apply similar changes to the [bw_csv] and [bw_geshi] shortcodes and their associated blocks oik-css/css and oik-css/geshi.

Requirements

  • Improve the support for loading content from a source file rather than being entered into the block
  • Improve the blocks to add a text field used to identify the file to be loaded.

Proposed solution

  • Implement the shared library file libs/class-oik-attachment-contents.php
  • Add a text field in the Settings area to accept the attachment ID, URL or file name
  • Update documentation with appropriate examples

WordPress embed block working differently between editor and front end

For a while now I've been using the WordPress embed block to embed content from another site / same site but have been noticing strange anomalies. Sometimes the embed works fine in the editor but doesn't display the same output in the front end.

Steps to reproduce

With / without oik

First attempt
I tried reproducing the problem in s.b/cwiccer, with a simple embed from the same site. ( s.b/cwiccer/gm ) It worked OK when oik wasn't activated but didn't when oik was activated. I'd chosen a bad example. The post ( entitled GM ) used the [bw_show_googlemap] shortcode.

Second attempt
Embedding sb/cwiccer/pagey-posts produced the same result regardless of oik's activation status.
image
Here you can tell that oik's activated since the [oik] shortcode has been expanded to oik

PHPUnit tests don't run unless oik-bwtrace is activated

When attempting to test oik-css after applying a fix it failed immediately

1) Tests_admin_oik_css::test_oik_css_options_bw_autop_enabled
Error: Call to undefined function bw_form_start()

Activating oik-bwtrace resolves the problem.

Determine if this is sensible requirement.

Note: oik-css delivers two blocks: CSS and GeSHi. These work even when oik is not activated, but the admin page is dependent upon oik.

Disable GeSHI's keyword linking

As noted in #7, when syntax highlighting with lang=html5, then HTML tags are linked to December.com. More often than not these links aren't wanted as they lead to outdated documentation.

And since there aren't any links for some languages it would make sense to turn them off for all languages.

Default GeSHi processing and my comments

lang Links to comments
css -
html http://december.com/html/4/element/{FNAMEL}.html HTML 4! and unwanted adverts
html5 http://december.com/html/4/element/{FNAMEL}.html HTML 4! and unwanted adverts
javascript -
jquery http://docs.jquery.com/{group}/{FNAME} Links to jQuery function group
mysql http://search.oracle.com/search/search?group=MySQL&amp;q={FNAME} or http://dev.mysql.com/doc/refman/%35%2E%31/en Oracle Search link fairly pathetic
php http://www.php.net/{FNAMEL}

Proposed solution

They should to be disabled, for all languages, using

$geshi->enable_keyword_links(false);

This also means replacing the use of geshi_highlight() with our own function bw_geshi_highlight().

Note: For Syntax highlighting of PHP we can use the [bw_api] shortcode https://www.oik-plugins.com/oik_shortcodes/bw_api/ This will produce links to PHP and oik's documentation of WordPress APIs: core, plugins and themes.

Add support for MySQL to [bw_geshi]

For oik-requests the [bw_sql] shortcode would benefit from having the SQL formatted using GeSHi.

Proposed solution

Add support for the GeSHI mysql.php formatter
Syntax:

[bw_geshi mysql] 
SELECT option_name,  option_value FROM wp_options WHERE autoload = 'yes'
[/bw_geshi]

Support PHP 7.2

oik-css uses GeSHI for pretty printing of code samples using the [bw_geshi] shortcode.

Actual output

This produces the following message under PHP 7.2

Deprecated: Function create_function() is deprecated in C:\apache\htdocs\wordpress\wp-content\plugins\oik-css\geshi\geshi.php on line 4751

Expected output

No messages

Explanation

The GeSHi code contains the deprecated create_function.

Proposed solution

Update the version of GeSHi.

  • The version currently included is 1.0.8.12.
  • The latest version is 1.0.9.0.
  • Since this version has not yet been changed for PHP 7.2 we’ll have to do it ourselves.
  • I raised an Issue GeSHi/geshi-1.0#98
  • A pull request was created. See GeSHi/geshi-1.0#100
  • Create unit tests that will produce messages under 7.2 until the deprecated logic has been removed.
  • Apply the pull request to a local copy of the repository.
  • Copy the changed files to oik-css

GeSHI links:

Note: oik-css will use another version of GeSHi if it has already been loaded by another plugin. This is because it was being used alongside wp-syntax; a long time ago. If the other version which has already been loaded is back level then the Deprecated message may appear. Should we test for this? Or is the deprecated message good enough. I’d say the latter.

Test bw_better_autop() with WordPress 4.7

During testing of WordPress 4.7-beta3 ( & 4 ) the following message was displayed when WP_DEBUG is true.

Notice: Indirect modification of overloaded element of WP_Hook has no effect in C:\apache\htdocs\wordpress\wp-content\plugins\oik\includes\oik-filters.inc on line 67

oik-css uses the bw_replace_filter() function from oik's includes/oik-filters.inc
This function sees $wp_filters as a multi-dimensional array.

The Notice is issued from

    $saved =& $wp_filter[$tag][$priority][$function_to_replace];

In WordPress 4.7 the $wp_filter array is of WP_Hook objects.

This issue is associated with another issue in the oik base plugin. bobbingwide/oik#58

Add media= parameter to [bw_css] for easy @media queries

I recently added some custom CSS to a page to style the output from [bw_related]
When I viewed it on my iPhone I found that the Cost field was overriding the title.
It was just too narrow.
The pragmatic solution was to alter the position of the Cost field for every display.
But I would have preferred to only have done this for narrow displays.
I would have used a CSS @media rule, if I could remember the syntax.
I thought that [bw_css] could help by allowing a media= parameter.
bw_css would wrap any content inside a @media query.

The default would be @media only screen and ( max-width: . valuepx ) {
when value is an integer.

[bw_geshi] - Do not eliminate p and br tags when lang=html or html5

For the [bw_geshi] shortcode when the lang= parameter is a certain value we need to undo some of the processing performed by other filters attached to the_content. For some languages this means eliminating unwanted paragraphs and breaks.

This is not the case for html and html5.

We also have ‘none’, which is intended for formatting examples of shortcodes.

Expected output

<p>What happens <b>here</b>?</p>

Actual output

What happens <b>here</b>?

Notes:

  • Syntax highlighting is not being performed for lang=html. This is a bug.
  • For lang=html5 the tags are linked to December.com. We don’t want them, so they need to be disabled using $geshi->enable_keyword_links(false);. See #8

Proposed solution

  • Create shortcode examples for each language, including none.
  • Implement tests for these examples - making them pass with the actual output, even when it's not expected.
  • Update to latest source from GeSHi and re-test.
  • Correct the logic so that p and br tags are shown for html and html5.
  • Update tests to reflect the expected result.
  • Check what happens for lang=none
  • Check whether or not html5 should be listed in the options for the lang= parameter.

Note: It may be necessary to revisit the hooks attached to the_content and other places where the shortcode may be expanded. Basically, we don’t want any wpautop logic applied to the content between [bw_geshi] and [/bw_geshi].

Remove redundant logic and files for `oik_css_activation()`

While running npm run makepot I noticed a message associated with a missing translators comment in admin/oik-activation.php.

  • For __( '%1$s may not be fully functional.', null)
  • I updated the code in oik-css but questioned the necessity/validity of this change.
  • During oik-zip processing the file is copied from oik's shared libraries.

Note: The translators comment is not missing from oik; there's another file that uses the same translatable text - admin/oik-activation.php

Explanation

  • Many moons ago I implemented shared libraries in oik-css so that it was no longer dependent upon oik.
  • The code in oik_css_activation() still exists, but is not invoked.

Proposed solution

  • The oik_css_activation() function can therefore be removed
  • admin/oik-activation.php is not required either.
  • So we don't have to worry about the missing translator's comment.

Update PHPUnit tests to PHPUnit 8 and WordPress 5.3.2

Update the PHPUnit tests so that they run under PHPUnit 8 with WordPress 5.3.2

  • Change setUp to return void
  • Add name to testsuite
  • Ensure wp_generate_attachment_metadata is available
- 1) Tests_shortcodes_oik_background::test_bw_background
Error: Call to undefined function wp_generate_attachment_metadata()

Not all oik-css/css block styling gets applied in the block editor

In a demo of the CSS block at WordPress Cambridge I noticed that styling of the h2 tag didn't take effect in the block editor.
Analysis shows that there's some Gutenberg CSS, in gutenberg/build/block-library/reset.css
that overrides the server side rendered CSS produced by the block.

html :where(.editor-styles-wrapper) h1, html :where(.editor-styles-wrapper) h2, html :where(.editor-styles-wrapper) h3, html :where(.editor-styles-wrapper) h4, html :where(.editor-styles-wrapper) h5, html :where(.editor-styles-wrapper) h6 {
    color: revert;
    font-size: revert;
    font-weight: revert;
    line-height: revert;
    margin: revert;

Can anything be done about this?

Note: If you do want to style h2 tags then you can use !important in the CSS.
Should the block do this automatically, or should it be a documented limitation?

Update for WordPress 5.8 compatibility

The oik-css plugin was originally built using webpack.

When used in WordPress 5.8 the Widget block editor produces a "doing it wrong" message due to the enqueueing of wp-editor.
It seems the best solution is to rework the code to build it using wp-scripts which will enable use of

import ServerSideRender from '@wordpress/server-side-render';

See bobbingwide/bobbingwide#30 (comment)

Requirements

  • Ability to use the Widget block editor without getting messages regarding wp-editor.
  • Which means changing the build to allow the import above.
  • Build using wp-scripts
  • Register each block using block.json
  • Ensure each block can be selected
  • Add some typography settings similar to UK tides

Proposed solution

  • Copy and cobble the solution developed for oik-magnetic-poetry, as this is now ahead of sb-starting-block
  • Remove unnecessary files: webpack.config.js and .babelrc
  • Change package.json for oik-css
  • Change block.json for each block: oik-css/css and oik-css/geshi
  • Change oik-css/index.js and oik-geshi\index.js to register the block from block.json
  • Change oik-css.php to register the blocks from block.json
  • Change oik-css.php to use get_block_wrapper_attributes()
  • Update node_modules and rebuild

Process for updating node_modules

  1. Remove the existing node_modules folder
  2. npm install
  3. npm install @wordpress/scripts --save-dev

See https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/

This worked first time! In the next plugin just 1. and 2. or 1. and 3. and see if the build works

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.