Table of contents
1.
Introduction
2.
About Web2Py
3.
MARKMIN Basics
4.
Oembed Protocol
5.
Referencing Wiki Content
6.
Frequently Asked Questions
6.1.
What is web2py used for?
6.2.
Which is better, web2py or Django?
6.3.
Should I learn web2py?
6.4.
Does web2py support Python 3?
6.5.
Is web2py a good framework?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

MARKMIN basics and Oembed protocol in web2py

Author Amit Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we will learn about MARKMIN basics and Oembed protocol in web2py.

But before we get into that, we will learn about the Web2Py framework which is a framework of Python Programming Language.

title

About Web2Py

Web2py can be understood as a free, open-source web framework for agile development which involves database-driven web applications; it is written in Python and programmable in Python. It is a full-stack framework consisting of all the components a developer needs to build a fully functional web application.

web2py

MARKMIN Basics

Markmin can be understood as a markup language included with Web2py. It is intended to be straightforward, quick, and simple to expand. It supports HTML5, floating pictures, auto-links, class style, tables, LaTeX formulas (via Google), syntax highlighting (with web2py CODE aid), and in-text citations.

Using the MARKMIN syntax, 

  • you can mark up text as bold by using **bold**, 
  • italic by using "italic," and 
  • code by using double inverted quotes. 
  • Sections must be preceded by a ##, 
  • sub-sections by a ###, and 
  • titles by a #. 
  • Prefix unordered items with a minus (-).
  • Similarly, prefix ordered items with a plus (+).
  • Links are created automatically from URLs.

 

Let’s check out an example of markmin text:

Source Output
# title title
## section section
### subsection subsection
**bold** bold
''italic'' italic
~~strikeout~~ strikeout
``verbatim`` verbatim
``color with **bold**``:red color with bold
``many colors``:color[blue:#ffff00] many colors
http://google.com http://google.com

Learn more at: Web2py

You can send more rendering rules to the MARKMIN helper by using the “extra” argument of “auth.wiki”.

“auth.wiki” is more robust than the basic MARKMIN helpers that support oembed and components.

To expose functions to your wiki, utilize the “env’ parameter of “auth.wiki”. Let’s check out an example:

auth.wiki(env=dict(join=lambda a:"-".join(a.split(","))))
You can also try this code with Online Python Compiler
Run Code

 

This allows us to access the markup syntax:

@{join:5,8,1}
You can also try this code with Online Python Compiler
Run Code

 

This will output as “5-8-1'' and executes the join function using the arguments "5,8,1" that were supplied to env.

Oembed Protocol

protocol

Oembed is a format that enables an embedded URL representation on outside websites. When a user shares a link to a resource, the straightforward API enables a website to display embedded content (such photographs or videos) without having to explicitly parse the resource.

Any URL can be entered (or copied and pasted) into a wiki page and will be displayed as a link to that URL. 

But there are some exceptions:

  • The link is incorporated as an image if the URL contains an image extension.
  • The link is included as HTML5 audio if the URL includes an audio extension.
  • The link is included as an HTML5 video if the URL includes a video extension.
  • If the URL ends in MS Office or PDF, Google Doc Viewer is embedded and displays the document's content (it only works for public documents).
  • Web2py contacts the relevant web service and inquires about the right way to embed the material if the URL leads to a YouTube, Vimeo, or Flickr website. To accomplish this, the oembed protocol is used.

 

The full list of supported formats is provided below:

Image (.PNG, .JPG, .JPEG, .GIF)
Audio (.WAV, .OGG, .MP3)
Video (.MOV, .MPE, .MP4, .MPG, .MPG2, .MPEG, .MPEG4, .MOVIE)

 

These are the formats that are supported through Google Doc Viewer:

Microsoft Excel (.XLS and .XLSX)
Microsoft PowerPoint 2007 / 2010 (.PPTX)
Apple Pages (.PAGES)
Adobe PDF (.PDF)
Adobe Illustrator (.AI)
Adobe Photoshop (.PSD)
Autodesk AutoCad (.DXF)
Scalable Vector Graphics (.SVG)
PostScript (.EPS, .PS)
TrueType (.TTF)
xml Paper Specification (.XPS)

 

These are the formats that are supported by the oembed protocol:

youtube.com
hulu.com
vimeo.com
flickr.com
slideshare.net
polleverywhere.com
wordpress.com
revision3.com
qik.com
viddler.com

 

This is the implementation that is done in the web2py file gluon.contrib.autolinks and specifically in the function expand_one. You can extend oembed support by registering more services.

This is achieved by adding an entry to the list i.e., “EMBED_MAPS”:

from gluon.contrib.autolinks import EMBED_MAPS
EMBED_MAPS.append((re.compile('http://youtube.com/\S*'),
                   'http://youtube.com/api/oembed.json'))
You can also try this code with Online Python Compiler
Run Code

 

youtube

Referencing Wiki Content

If you want to create a wiki page with the slug "contactus," you can refer to this page as

@////15/codingninjas.jpg
You can also try this code with Online Python Compiler
Run Code

 

Here @//// means

@/app/controller/function
You can also try this code with Online Python Compiler
Run Code

 

However, because "app," "controller," and "function" are lacking, default is assumed.

Similarly, you can submit a media asset (such as an image) that is connected to the page using the wiki menu. All of the files you have uploaded are displayed on the "manage media" tab, along with the correct syntax for linking media files. The link phrase will look like this if, for instance, you upload a file with the name "beach" and the extension "test.jpg."

@////15/codingninjas.jpg
You can also try this code with Online Python Compiler
Run Code

 

There is a prefix @//// that is identical to the one that is previously described. The record holding the media file has the id 15. “codingninjas'' is the name of the image, and the original file's extension is “.jpg.”

“@////15/beach.jpg” can be embedded into wiki pages by copying and pasting.

Be aware that media files are connected to pages and receive access rights from the pages.

Frequently Asked Questions

What is web2py used for?

Python dynamic web content programming is made possible via Web2py. Web2py is made to make laborious web development jobs more accessible, such as creating web forms from scratch, while a web developer can still do it if necessary.

Which is better, web2py or Django?

Due to its smaller size, short learning curve, and lack of project-level configuration files, web2py differs from Django. Compared to PHP-based frameworks and Java-based frameworks, web2py is far less verbose and has a lot clearer syntax. This makes applications easier to comprehend, maintain, and create.

Should I learn web2py?

More than web-development purposes, web2py is primarily used as a teaching tool. Because of its graphical interface and built-in web IDE, it makes it easy for the developer to learn server-side web development.

Does web2py support Python 3?

web2py actually runs with CPython (the C implementation) and PyPy (Python written in Python) on Python 2.7 and Python 3.

Is web2py a good framework?

To summarize, Web2py is a free, fast, secure web development framework that is entirely written in python and encourages using python in every way possible (model, view, controller). It is an excellent framework for small web applications or prototypes but fails to fulfill the enterprise-class quality requirements.

Conclusion

In this article, we learned markmin basics and oembed protocol in web2py. After reading about markmin and oembed in web2py, are you not feeling excited to read/explore more articles on the topic of web2py? Don't worry; Coding Ninjas has you covered. 

To learn more about this, see wiki components to authenticate that wiki in web2py and sqlform and insert/update/delete in web2py.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Merry Learning

Live masterclass