@@ -33,21 +33,8 @@ mimewritable{mime}(::MIME{mime}, x) =
33
33
show (io:: IO , m:: AbstractString , x) = show (io, MIME (m), x)
34
34
mimewritable (m:: AbstractString , x) = mimewritable (MIME (m), x)
35
35
36
- abstract MIMETypeType
37
-
38
- immutable IsText <: MIMETypeType end
39
- immutable IsBytes <: MIMETypeType end
40
-
41
36
verbose_show (io, m, x) = show (IOContext (io,limit= false ), m, x)
42
37
43
- """
44
- MIME types are assumed to be binary data except for a set of types known to be
45
- text data (possibly Unicode). `mimetypetype(m)` returns `Multimedia.IsText` or
46
- `Multimedia.IsBytes` for text or binary data respectively.
47
- """
48
- Base. @pure mimetypetype {M} (:: MIME{M} ) =
49
- startswith (string (M), " text/" ) ? IsText () : IsBytes ()
50
-
51
38
"""
52
39
reprmime(mime, x)
53
40
@@ -65,20 +52,20 @@ As a special case, if `x` is an `AbstractString` (for textual MIME types) or a
65
52
special case does not apply to the `"text/plain"` MIME type. This is useful so
66
53
that raw data can be passed to `display(m::MIME, x)`.
67
54
"""
68
- reprmime (m:: MIME , x) = reprmime (mimetypetype (m), m, x)
69
- reprmime (:: IsText , m:: MIME , x) = sprint (verbose_show, m, x)
55
+ reprmime (m:: MIME , x) = istextmime (m) ? _textreprmime (m, x) : _binreprmime (m, x)
70
56
71
57
# strings are shown escaped for text/plain
72
- reprmime (:: IsText , :: MIME , x:: AbstractString ) = x
73
- reprmime (:: IsText , m:: MIME"text/plain" , x:: AbstractString ) =
58
+ _textreprmime (m:: MIME , x) = sprint (verbose_show, m, x)
59
+ _textreprmime (:: MIME , x:: AbstractString ) = x
60
+ _textreprmime (m:: MIME"text/plain" , x:: AbstractString ) =
74
61
sprint (verbose_show, m, x)
75
62
76
- function reprmime ( :: IsBytes , m:: MIME , x)
63
+ function _binreprmime ( m:: MIME , x)
77
64
s = IOBuffer ()
78
65
verbose_show (s, m, x)
79
66
takebuf_array (s)
80
67
end
81
- reprmime ( :: IsBytes , m:: MIME , x:: Vector{UInt8} ) = x
68
+ _binreprmime ( m:: MIME , x:: Vector{UInt8} ) = x
82
69
83
70
"""
84
71
stringmime(mime, x)
@@ -87,30 +74,32 @@ Returns an `AbstractString` containing the representation of `x` in the
87
74
requested `mime` type. This is similar to [`reprmime`](:func:`reprmime`) except
88
75
that binary data is base64-encoded as an ASCII string.
89
76
"""
90
- stringmime (m:: MIME , x) = stringmime ( mimetypetype (m), m, x)
91
- stringmime ( :: IsText , m :: MIME , x) = reprmime (m, x)
92
- stringmime ( :: IsBytes , m:: MIME , x) = base64encode (verbose_show, m, x)
93
- stringmime ( :: IsBytes , m:: MIME , x:: Vector{UInt8} ) = base64encode (write, x)
77
+ stringmime (m:: MIME , x) = istextmime (m) ? reprmime (m, x) : _binstringmime ( m, x)
78
+
79
+ _binstringmime ( m:: MIME , x) = base64encode (verbose_show, m, x)
80
+ _binstringmime ( m:: MIME , x:: Vector{UInt8} ) = base64encode (write, x)
94
81
95
82
"""
96
83
istextmime(m::MIME)
97
84
98
- Determine whether a MIME type is text data.
85
+ Determine whether a MIME type is text data. MIME types are assumed to be binary
86
+ data except for a set of types known to be text data (possibly Unicode).
99
87
"""
100
- istextmime (m:: MIME ) = isa ( mimetypetype (m), IsText )
88
+ istextmime (m:: MIME ) = startswith ( string (m), " text/ " )
101
89
102
90
# it is convenient to accept strings instead of ::MIME
103
91
istextmime (m:: AbstractString ) = istextmime (MIME (m))
104
92
reprmime (m:: AbstractString , x) = reprmime (MIME (m), x)
105
93
stringmime (m:: AbstractString , x) = stringmime (MIME (m), x)
106
94
107
95
for mime in [" application/atom+xml" , " application/ecmascript" ,
108
- " application/javascript" , " application/julia" , " application/json" ,
109
- " application/postscript" , " application/rdf+xml" , " application/rss+xml" ,
110
- " application/x-latex" , " application/xhtml+xml" , " application/xml" ,
111
- " application/xml-dtd" , " image/svg+xml" , " model/vrml" , " model/x3d+vrml" ,
112
- " model/x3d+xml" ]
113
- mimetypetype (:: MIME{Symbol(mime)} ) = IsText ()
96
+ " application/javascript" , " application/julia" ,
97
+ " application/json" , " application/postscript" ,
98
+ " application/rdf+xml" , " application/rss+xml" ,
99
+ " application/x-latex" , " application/xhtml+xml" , " application/xml" ,
100
+ " application/xml-dtd" , " image/svg+xml" , " model/vrml" ,
101
+ " model/x3d+vrml" , " model/x3d+xml" ]
102
+ istextmime (:: MIME{Symbol(mime)} ) = true
114
103
end
115
104
116
105
# ##########################################################################
0 commit comments