Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

# -*- encoding: utf-8 -*- 

r""" 

Rich Output for the Browser 

""" 

 

from sage.repl.rich_output.output_basic import OutputBase 

from sage.repl.rich_output.buffer import OutputBuffer 

 

 

class OutputHtml(OutputBase): 

 

def __init__(self, html): 

""" 

HTML Output 

 

INPUT: 

 

- ``html`` -- 

:class:`~sage.repl.rich_output.buffer.OutputBuffer`. Alternatively, 

a string (bytes) can be passed directly which will then be 

converted into an 

:class:`~sage.repl.rich_output.buffer.OutputBuffer`. String 

containing the html fragment code. Excludes the surrounding 

``<body>`` and ``<html>`` tag. 

 

EXAMPLES:: 

 

sage: from sage.repl.rich_output.output_catalog import OutputHtml 

sage: OutputHtml('<div>Foo<b>B</b>ar</div>') 

OutputHtml container 

""" 

self.html = OutputBuffer(html) 

 

@classmethod 

def example(cls): 

r""" 

Construct a sample Html output container 

 

This static method is meant for doctests, so they can easily 

construct an example. 

 

OUTPUT: 

 

An instance of :class:`OutputHtml`. 

 

EXAMPLES:: 

 

sage: from sage.repl.rich_output.output_catalog import OutputHtml 

sage: OutputHtml.example() 

OutputHtml container 

sage: OutputHtml.example().html.get_str() 

'<div>Hello World!</div>' 

""" 

return cls('<div>Hello World!</div>') 

 

def print_to_stdout(self): 

r""" 

Write the data to stdout. 

 

This is just a convenience method to help with debugging. 

 

EXAMPLES:: 

 

sage: from sage.repl.rich_output.output_catalog import OutputHtml 

sage: rich_output = OutputHtml.example() 

sage: rich_output.print_to_stdout() 

<div>Hello World!</div> 

""" 

print(self.html.get_unicode()) 

 

def with_html_tag(self): 

r""" 

Return the HTML code surrounded by ``<html>`` tag 

 

This is just a convenience method. 

 

EXAMPLES:: 

 

sage: from sage.repl.rich_output.output_catalog import OutputHtml 

sage: rich_output = OutputHtml.example() 

sage: rich_output.print_to_stdout() 

<div>Hello World!</div> 

sage: rich_output.with_html_tag() 

'<html><div>Hello World!</div></html>' 

""" 

return '<html>{0}</html>'.format(self.html.get_unicode())